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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Pulse.Elaborate.fst | Pulse.Elaborate.elab_comp_close_commute | val elab_comp_close_commute (c:comp) (x:var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x) | val elab_comp_close_commute (c:comp) (x:var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x) | let elab_comp_close_commute (c:comp) (x:var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x)
= RT.close_term_spec (elab_comp c) x;
elab_comp_close_commute' c x 0 | {
"file_name": "lib/steel/pulse/Pulse.Elaborate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 34,
"end_line": 141,
"start_col": 0,
"start_line": 138
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Elaborate
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Elaborate.Core
// let rec elab_term_bv_sort (t:term)
// : Lemma
// (ensures
// (R.Tv_Var? (R.inspect_ln (elab_term t)) \/
// R.Tv_BVar? (R.inspect_ln (elab_term t))) ==>
// (match R.inspect_ln (elab_term t) with
// | R.Tv_Var bv
// | R.Tv_BVar bv ->
// let vv = R.inspect_bv bv in
// vv.bv_sort == RT.tun))
// = admit()
#push-options "--fuel 10 --ifuel 10 --z3rlimit_factor 30 --query_stats --z3cliopt 'smt.qi.eager_threshold=100'"
let rec elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
// | Tm_PureApp e1 _ e2 ->
// elab_open_commute' e1 v n;
// elab_open_commute' e2 v n
| Tm_Inv p ->
elab_open_commute' p v n
| Tm_Pure p ->
elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> ()
let elab_comp_open_commute' (c:comp) (v:term) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.DT n (elab_term v) ] ==
elab_comp (open_comp' c v n))
= match c with
| C_Tot t -> elab_open_commute' t v n
| C_ST s
| C_STGhost s ->
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_open_commute' inames v n;
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
let rec elab_close_commute' (e:term)
(v:var)
(n:index)
: Lemma (ensures (
RT.subst_term (elab_term e) [ RT.ND v n ] ==
elab_term (close_term' e v n)))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
| Tm_Inv p ->
elab_close_commute' p v n
| Tm_Pure p ->
elab_close_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_close_commute' e1 v n;
elab_close_commute' e2 v n
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_close_commute' t.binder_ty v n;
elab_close_commute' body v (n + 1)
| Tm_FStar _ -> ()
let elab_comp_close_commute' (c:comp) (v:var) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.ND v n ] ==
elab_comp (close_comp' c v n))
(decreases c)
= match c with
| C_Tot t -> elab_close_commute' t v n
| C_ST s
| C_STGhost s ->
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_close_commute' inames v n;
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
let elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x)
= RT.open_term_spec (elab_term t) x;
elab_open_commute' t (null_var x) 0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Elaborate.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Naming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"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": 10,
"initial_ifuel": 10,
"max_fuel": 10,
"max_ifuel": 10,
"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.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 30,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Pulse.Syntax.Base.comp -> x: Pulse.Syntax.Base.var
-> FStar.Pervasives.Lemma
(ensures
Pulse.Elaborate.Pure.elab_comp (Pulse.Syntax.Naming.close_comp c x) ==
FStar.Reflection.Typing.close_term (Pulse.Elaborate.Pure.elab_comp c) x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.var",
"Pulse.Elaborate.elab_comp_close_commute'",
"Prims.unit",
"FStar.Reflection.Typing.close_term_spec",
"Pulse.Elaborate.Pure.elab_comp",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Stubs.Reflection.Types.term",
"Pulse.Syntax.Naming.close_comp",
"FStar.Reflection.Typing.close_term",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let elab_comp_close_commute (c: comp) (x: var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x) =
| RT.close_term_spec (elab_comp c) x;
elab_comp_close_commute' c x 0 | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.equals_instr | val equals_instr (x1 x2: instr_t_record) : Type0 | val equals_instr (x1 x2: instr_t_record) : Type0 | let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 28,
"start_col": 0,
"start_line": 27
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | x1: Vale.X64.Instruction_s.instr_t_record -> x2: Vale.X64.Instruction_s.instr_t_record -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.instr_t_record",
"Prims.squash",
"Prims.eq2"
] | [] | false | false | false | true | true | let equals_instr (x1 x2: instr_t_record) : Type0 =
| squash (x1 == x2) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.ins | val ins : Type0 | let ins = BC.instruction_t instr_annotation | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 44,
"start_col": 0,
"start_line": 44
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation"
] | [] | false | false | false | true | true | let ins =
| BC.instruction_t instr_annotation | false |
|
Pulse.Elaborate.fst | Pulse.Elaborate.elab_open_commute | val elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x) | val elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x) | let elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x)
= RT.open_term_spec (elab_term t) x;
elab_open_commute' t (null_var x) 0 | {
"file_name": "lib/steel/pulse/Pulse.Elaborate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 39,
"end_line": 136,
"start_col": 0,
"start_line": 133
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Elaborate
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Elaborate.Core
// let rec elab_term_bv_sort (t:term)
// : Lemma
// (ensures
// (R.Tv_Var? (R.inspect_ln (elab_term t)) \/
// R.Tv_BVar? (R.inspect_ln (elab_term t))) ==>
// (match R.inspect_ln (elab_term t) with
// | R.Tv_Var bv
// | R.Tv_BVar bv ->
// let vv = R.inspect_bv bv in
// vv.bv_sort == RT.tun))
// = admit()
#push-options "--fuel 10 --ifuel 10 --z3rlimit_factor 30 --query_stats --z3cliopt 'smt.qi.eager_threshold=100'"
let rec elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
// | Tm_PureApp e1 _ e2 ->
// elab_open_commute' e1 v n;
// elab_open_commute' e2 v n
| Tm_Inv p ->
elab_open_commute' p v n
| Tm_Pure p ->
elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> ()
let elab_comp_open_commute' (c:comp) (v:term) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.DT n (elab_term v) ] ==
elab_comp (open_comp' c v n))
= match c with
| C_Tot t -> elab_open_commute' t v n
| C_ST s
| C_STGhost s ->
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_open_commute' inames v n;
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
let rec elab_close_commute' (e:term)
(v:var)
(n:index)
: Lemma (ensures (
RT.subst_term (elab_term e) [ RT.ND v n ] ==
elab_term (close_term' e v n)))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
| Tm_Inv p ->
elab_close_commute' p v n
| Tm_Pure p ->
elab_close_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_close_commute' e1 v n;
elab_close_commute' e2 v n
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_close_commute' t.binder_ty v n;
elab_close_commute' body v (n + 1)
| Tm_FStar _ -> ()
let elab_comp_close_commute' (c:comp) (v:var) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.ND v n ] ==
elab_comp (close_comp' c v n))
(decreases c)
= match c with
| C_Tot t -> elab_close_commute' t v n
| C_ST s
| C_STGhost s ->
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_close_commute' inames v n;
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Elaborate.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Naming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"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": 10,
"initial_ifuel": 10,
"max_fuel": 10,
"max_ifuel": 10,
"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.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 30,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> x: Pulse.Syntax.Base.var
-> FStar.Pervasives.Lemma
(ensures
Pulse.Elaborate.Pure.elab_term (Pulse.Syntax.Naming.open_term t x) ==
FStar.Reflection.Typing.open_term (Pulse.Elaborate.Pure.elab_term t) x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Elaborate.elab_open_commute'",
"Pulse.Syntax.Pure.null_var",
"Prims.unit",
"FStar.Reflection.Typing.open_term_spec",
"Pulse.Elaborate.Pure.elab_term",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Stubs.Reflection.Types.term",
"Pulse.Syntax.Naming.open_term",
"FStar.Reflection.Typing.open_term",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let elab_open_commute (t: term) (x: var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x) =
| RT.open_term_spec (elab_term t) x;
elab_open_commute' t (null_var x) 0 | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.codes | val codes : Type0 | let codes = BC.codes_t instr_annotation | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 47,
"start_col": 0,
"start_line": 47
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Bytes_Code_s.codes_t",
"Vale.X64.Machine_Semantics_s.instr_annotation"
] | [] | false | false | false | true | true | let codes =
| BC.codes_t instr_annotation | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.ocmp | val ocmp : Prims.eqtype | let ocmp = BC.ocmp | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 45,
"start_col": 0,
"start_line": 45
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Bytes_Code_s.ocmp"
] | [] | false | false | false | true | false | let ocmp =
| BC.ocmp | false |
|
Vale.X64.Instructions_s.fst | Vale.X64.Instructions_s.ins_SHA256_rnds2 | val ins_SHA256_rnds2 :
instr_dep [inOut opXmm] [opXmm; oneXmm (OReg 0)] PreserveFlags eval_SHA256_rnds2 | val ins_SHA256_rnds2 :
instr_dep [inOut opXmm] [opXmm; oneXmm (OReg 0)] PreserveFlags eval_SHA256_rnds2 | let ins_SHA256_rnds2 =
make_ins (fun dst src -> Print "sha256rnds2" PrintPSha256rnds2 [PXmm dst; PXmm src]) | {
"file_name": "vale/specs/hardware/Vale.X64.Instructions_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 126,
"start_col": 0,
"start_line": 125
} | module Vale.X64.Instructions_s
open FStar.Mul
friend Vale.X64.Instruction_s // We're part of the trusted specification, so we can friend Instruction_s
let ins_Mov64 = make_ins (fun dst src -> print_s "mov" [P64 dst; P64 src])
let ins_MovBe64 = make_ins (fun dst src -> print_s "movbe" [P64 dst; P64 src])
let ins_Bswap64 = make_ins (fun dst -> print_s "bswap" [P64 dst])
let ins_Cmovc64 = make_ins (fun dst src -> print_s "cmovc" [P64 dst; P64 src])
let ins_Add64 = make_ins (fun dst src -> print_s "add" [P64 dst; P64 src])
let ins_AddLea64 =
make_ins (fun (dst src1 src2:operand64) ->
let m =
match (src1, src2) with
| (OReg r1, OConst i2) -> MReg (Reg 0 r1) i2
| (OReg r1, OReg r2) -> MIndex (Reg 0 r1) 1 (Reg 0 r2) 0
| _ -> MConst pow2_128 // Shouldn't hit this, but if we do, assembler will complain
in
let m = (m, Public) in // taint is not actually printed; we're just using OMem for its printer
// TODO: what's the right suffix here?
// print_s "lea" [P64 dst; P64 (OMem m)])
print "lea" [P64 dst; P64 (OMem m)])
let ins_AddCarry64 = make_ins (fun dst src -> print_s "adc" [P64 dst; P64 src])
let ins_Adcx64 = make_ins (fun dst src -> print_s "adcx" [P64 dst; P64 src])
let ins_Adox64 = make_ins (fun dst src -> print_s "adox" [P64 dst; P64 src])
let ins_Sub64 = make_ins (fun dst src -> print_s "sub" [P64 dst; P64 src])
let ins_Sbb64 = make_ins (fun dst src -> print_s "sbb" [P64 dst; P64 src])
let ins_Mul64 = make_ins (fun src -> print_s "mul" [P64 src])
let ins_Mulx64 =
make_ins (fun dst_hi dst_lo src -> print_s "mulx" [P64 dst_hi; P64 dst_lo; P64 src])
let ins_IMul64 = make_ins (fun dst src -> print_s "imul" [P64 dst; P64 src])
let ins_And64 = make_ins (fun dst src -> print_s "and" [P64 dst; P64 src])
let ins_Xor64 = make_ins (fun dst src -> print_s "xor"
// special idiom for zeroing r: xor64 r, r --> xor32 r, r
(if OReg? dst && dst = src then [P32 dst; P32 src] else [P64 dst; P64 src]))
let ins_Shr64 = make_ins (fun dst amt -> print_s "shr" [P64 dst; PShift amt])
let ins_Shl64 = make_ins (fun dst amt -> print_s "shl" [P64 dst; PShift amt])
let ins_Cpuid = make_ins (print "cpuid" [])
let ins_Xgetbv = make_ins (print "xgetbv" [])
let ins_Movdqu = make_ins (fun dst src -> print "movdqu" [PXmm dst; PXmm src])
let ins_Pxor = make_ins (fun dst src -> print "pxor" [PXmm dst; PXmm src])
let ins_VPxor = make_ins (fun dst src1 src2 -> print "vpxor" [PXmm dst; PXmm src1; PXmm src2])
let ins_Pand = make_ins (fun dst src -> print "pand" [PXmm dst; PXmm src])
let ins_Paddd = make_ins (fun dst src -> print "paddd" [PXmm dst; PXmm src])
let ins_VPaddd = make_ins (fun dst src1 src2 -> print "vpaddd" [PXmm dst; PXmm src1; PXmm src2])
let ins_Pslld amt = make_ins (fun dst -> print "pslld" [PXmm dst; PImm amt])
let ins_Psrld amt = make_ins (fun dst -> print "psrld" [PXmm dst; PImm amt])
let ins_Psrldq amt = make_ins (fun dst -> print "psrldq" [PXmm dst; PImm amt])
let ins_Palignr amount =
make_ins (fun dst src -> print "palignr" [PXmm dst; PXmm src; PImm amount])
let ins_VPalignr amount =
make_ins (fun dst src1 src2 -> print "vpalignr" [PXmm dst; PXmm src1; PXmm src2; PImm amount])
let ins_Shufpd permutation =
make_ins (fun dst src -> print "shufpd" [PXmm dst; PXmm src; PImm permutation])
let ins_VShufpd permutation =
make_ins (fun dst src1 src2 -> print "vshufpd" [PXmm dst; PXmm src1; PXmm src2; PImm permutation])
let ins_Pshufb = make_ins (fun dst src -> print "pshufb" [PXmm dst; PXmm src])
let ins_VPshufb = make_ins (fun dst src1 src2 -> print "vpshufb" [PXmm dst; PXmm src1; PXmm src2])
let ins_Pshufd permutation =
make_ins (fun dst src -> print "pshufd" [PXmm dst; PXmm src; PImm permutation])
let ins_Pcmpeqd = make_ins (fun dst src -> print "pcmpeqd" [PXmm dst; PXmm src])
let ins_Pextrq index = make_ins (fun dst src -> print "pextrq" [P64 dst; PXmm src; PImm index])
let ins_Pinsrd index = make_ins (fun dst src -> print "pinsrd" [PXmm dst; P32 src; PImm index])
let ins_Pinsrq index = make_ins (fun dst src -> print "pinsrq" [PXmm dst; P64 src; PImm index])
let ins_VPslldq count = make_ins (fun dst src -> print "vpslldq" [PXmm dst; PXmm src; PImm count])
let ins_VPsrldq count = make_ins (fun dst src -> print "vpsrldq" [PXmm dst; PXmm src; PImm count])
let ins_Pclmulqdq imm = make_ins (fun dst src -> print "pclmulqdq" [PXmm dst; PXmm src; PImm imm])
let ins_VPclmulqdq imm =
make_ins (fun dst src1 src2 -> print "vpclmulqdq" [PXmm dst; PXmm src1; PXmm src2; PImm imm])
let ins_AESNI_enc = make_ins (fun dst src -> print "aesenc" [PXmm dst; PXmm src])
let ins_VAESNI_enc =
make_ins (fun dst src1 src2 -> print "vaesenc" [PXmm dst; PXmm src1; PXmm src2])
let ins_AESNI_enc_last = make_ins (fun dst src -> print "aesenclast" [PXmm dst; PXmm src])
let ins_VAESNI_enc_last =
make_ins (fun dst src1 src2 -> print "vaesenclast"[PXmm dst; PXmm src1; PXmm src2])
let ins_AESNI_dec = make_ins (fun dst src -> print "aesdec" [PXmm dst; PXmm src])
let ins_AESNI_dec_last = make_ins (fun dst src -> print "aesdeclast" [PXmm dst; PXmm src])
let ins_AESNI_imc = make_ins (fun dst src -> print "aesimc" [PXmm dst; PXmm src])
let ins_AESNI_keygen_assist imm =
make_ins (fun dst src -> print "aeskeygenassist" [PXmm dst; PXmm src; PImm imm]) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Instruction_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Instructions_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | Vale.X64.Instruction_s.instr_dep [Vale.X64.Instruction_s.inOut Vale.X64.Instruction_s.opXmm]
[Vale.X64.Instruction_s.opXmm; Vale.X64.Instruction_s.oneXmm (Vale.X64.Machine_s.OReg 0)]
Vale.X64.Instruction_s.PreserveFlags
Vale.X64.Instructions_s.eval_SHA256_rnds2 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.make_ins",
"Prims.Cons",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.opXmm",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.oneXmm",
"Vale.X64.Machine_s.OReg",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.eval_SHA256_rnds2",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Instruction_s.Print",
"Vale.X64.Instruction_s.PrintPSha256rnds2",
"Vale.X64.Instruction_s.instr_print_operand",
"Vale.X64.Instruction_s.PXmm",
"Vale.X64.Instruction_s.instr_print"
] | [] | false | false | false | false | false | let ins_SHA256_rnds2 =
| make_ins (fun dst src -> Print "sha256rnds2" PrintPSha256rnds2 [PXmm dst; PXmm src]) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.code | val code : Type0 | let code = BC.code_t instr_annotation | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 46,
"start_col": 0,
"start_line": 46
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Bytes_Code_s.code_t",
"Vale.X64.Machine_Semantics_s.instr_annotation"
] | [] | false | false | false | true | true | let code =
| BC.code_t instr_annotation | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.flag_val_t | val flag_val_t : Type0 | let flag_val_t = option bool | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 56,
"start_col": 7,
"start_line": 56
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"Prims.bool"
] | [] | false | false | false | true | true | let flag_val_t =
| option bool | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_mem128 | val eval_mem128 (ptr: int) (s: machine_state) : quad32 | val eval_mem128 (ptr: int) (s: machine_state) : quad32 | let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 102,
"end_line": 85,
"start_col": 7,
"start_line": 85
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> s: Vale.X64.Machine_Semantics_s.machine_state -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Arch.MachineHeap_s.get_heap_val128",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.Def.Types_s.quad32"
] | [] | false | false | false | true | false | let eval_mem128 (ptr: int) (s: machine_state) : quad32 =
| get_heap_val128 ptr (heap_get s.ms_heap) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_mem | val eval_mem (ptr: int) (s: machine_state) : nat64 | val eval_mem (ptr: int) (s: machine_state) : nat64 | let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 97,
"end_line": 84,
"start_col": 7,
"start_line": 84
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> s: Vale.X64.Machine_Semantics_s.machine_state -> Vale.Def.Types_s.nat64 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Arch.MachineHeap_s.get_heap_val64",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.Def.Types_s.nat64"
] | [] | false | false | false | true | false | let eval_mem (ptr: int) (s: machine_state) : nat64 =
| get_heap_val64 ptr (heap_get s.ms_heap) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_stack128 | val eval_stack128 (ptr: int) (s: machine_stack) : quad32 | val eval_stack128 (ptr: int) (s: machine_stack) : quad32 | let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 92,
"start_col": 7,
"start_line": 90
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> s: Vale.X64.Machine_Semantics_s.machine_stack -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.get_heap_val128",
"Vale.Def.Types_s.quad32"
] | [] | false | false | false | true | false | let eval_stack128 (ptr: int) (s: machine_stack) : quad32 =
| let Machine_stack _ mem = s in
get_heap_val128 ptr mem | false |
Pulse.Elaborate.fst | Pulse.Elaborate.elab_freevars | val elab_freevars (e:term)
: Lemma (freevars e == RT.freevars (elab_term e)) | val elab_freevars (e:term)
: Lemma (freevars e == RT.freevars (elab_term e)) | let elab_freevars e = elab_freevars_eq e | {
"file_name": "lib/steel/pulse/Pulse.Elaborate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 221,
"start_col": 0,
"start_line": 221
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Elaborate
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Elaborate.Core
// let rec elab_term_bv_sort (t:term)
// : Lemma
// (ensures
// (R.Tv_Var? (R.inspect_ln (elab_term t)) \/
// R.Tv_BVar? (R.inspect_ln (elab_term t))) ==>
// (match R.inspect_ln (elab_term t) with
// | R.Tv_Var bv
// | R.Tv_BVar bv ->
// let vv = R.inspect_bv bv in
// vv.bv_sort == RT.tun))
// = admit()
#push-options "--fuel 10 --ifuel 10 --z3rlimit_factor 30 --query_stats --z3cliopt 'smt.qi.eager_threshold=100'"
let rec elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
// | Tm_PureApp e1 _ e2 ->
// elab_open_commute' e1 v n;
// elab_open_commute' e2 v n
| Tm_Inv p ->
elab_open_commute' p v n
| Tm_Pure p ->
elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> ()
let elab_comp_open_commute' (c:comp) (v:term) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.DT n (elab_term v) ] ==
elab_comp (open_comp' c v n))
= match c with
| C_Tot t -> elab_open_commute' t v n
| C_ST s
| C_STGhost s ->
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_open_commute' inames v n;
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
let rec elab_close_commute' (e:term)
(v:var)
(n:index)
: Lemma (ensures (
RT.subst_term (elab_term e) [ RT.ND v n ] ==
elab_term (close_term' e v n)))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
| Tm_Inv p ->
elab_close_commute' p v n
| Tm_Pure p ->
elab_close_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_close_commute' e1 v n;
elab_close_commute' e2 v n
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_close_commute' t.binder_ty v n;
elab_close_commute' body v (n + 1)
| Tm_FStar _ -> ()
let elab_comp_close_commute' (c:comp) (v:var) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.ND v n ] ==
elab_comp (close_comp' c v n))
(decreases c)
= match c with
| C_Tot t -> elab_close_commute' t v n
| C_ST s
| C_STGhost s ->
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_close_commute' inames v n;
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
let elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x)
= RT.open_term_spec (elab_term t) x;
elab_open_commute' t (null_var x) 0
let elab_comp_close_commute (c:comp) (x:var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x)
= RT.close_term_spec (elab_comp c) x;
elab_comp_close_commute' c x 0
let elab_comp_open_commute (c:comp) (x:term)
: Lemma (elab_comp (open_comp_with c x) == RT.open_with (elab_comp c) (elab_term x))
= RT.open_with_spec (elab_comp c) (elab_term x);
elab_comp_open_commute' c x 0
let rec elab_ln t i =
match t.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_ln p i
| Tm_Pure t -> elab_ln t i
| Tm_AddInv l r
| Tm_Star l r ->
elab_ln l i;
elab_ln r i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_ln t.binder_ty i;
elab_ln body (i + 1)
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown
| Tm_FStar _ -> ()
let elab_ln_comp (c:comp) (i:int)
: Lemma (requires ln_c' c i)
(ensures RT.ln' (elab_comp c) i) =
match c with
| C_Tot t -> elab_ln t i
| C_ST st
| C_STGhost st ->
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1)
| C_STAtomic inames _ st ->
elab_ln inames i;
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1)
let rec elab_freevars_eq (e:term)
: Lemma (Set.equal (freevars e) (RT.freevars (elab_term e))) =
match e.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_freevars_eq p
| Tm_Pure t -> elab_freevars_eq t
| Tm_AddInv l r
| Tm_Star l r ->
elab_freevars_eq l;
elab_freevars_eq r
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_freevars_eq t.binder_ty;
elab_freevars_eq body
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown
| Tm_FStar _ -> ()
let elab_freevars_comp_eq (c:comp)
: Lemma (Set.equal (freevars_comp c) (RT.freevars (elab_comp c))) =
match c with
| C_Tot t -> elab_freevars_eq t
| C_ST st
| C_STGhost st ->
elab_freevars_eq st.res;
elab_freevars_eq st.pre;
elab_freevars_eq st.post
| C_STAtomic inames _ st ->
elab_freevars_eq inames;
elab_freevars_eq st.res;
elab_freevars_eq st.pre;
elab_freevars_eq st.post
#pop-options | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Elaborate.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Naming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Pulse.Syntax.Base.term
-> FStar.Pervasives.Lemma
(ensures
Pulse.Syntax.Naming.freevars e ==
FStar.Reflection.Typing.freevars (Pulse.Elaborate.Pure.elab_term e)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Elaborate.elab_freevars_eq",
"Prims.unit"
] | [] | true | false | true | false | false | let elab_freevars e =
| elab_freevars_eq e | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_reg_int | val eval_reg_int (r: reg) (s: machine_state) : int | val eval_reg_int (r: reg) (s: machine_state) : int | let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 90,
"end_line": 82,
"start_col": 7,
"start_line": 82
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | r: Vale.X64.Machine_s.reg -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.t_reg_to_int",
"Vale.X64.Machine_s.__proj__Reg__item__rf",
"Vale.X64.Machine_Semantics_s.eval_reg",
"Prims.int"
] | [] | false | false | false | true | false | let eval_reg_int (r: reg) (s: machine_state) : int =
| t_reg_to_int r.rf (eval_reg r s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_reg | val eval_reg (r: reg) (s: machine_state) : t_reg r | val eval_reg (r: reg) (s: machine_state) : t_reg r | let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 78,
"start_col": 7,
"start_line": 78
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | r: Vale.X64.Machine_s.reg -> s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_s.t_reg r | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_s.t_reg"
] | [] | false | false | false | false | false | let eval_reg (r: reg) (s: machine_state) : t_reg r =
| s.ms_regs r | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_ocmp_opaque | val eval_ocmp_opaque (s: machine_state) (c: ocmp) : bool | val eval_ocmp_opaque (s: machine_state) (c: ocmp) : bool | let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 124,
"start_col": 0,
"start_line": 124
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | s: Vale.X64.Machine_Semantics_s.machine_state -> c: Vale.X64.Machine_Semantics_s.ocmp -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_Semantics_s.eval_ocmp",
"Prims.bool"
] | [] | false | false | false | true | false | let eval_ocmp_opaque (s: machine_state) (c: ocmp) : bool =
| eval_ocmp s c | false |
Hacl.Spec.PrecompTable.fst | Hacl.Spec.PrecompTable.table_select_loop_lemma | val table_select_loop_lemma:
#t:limb_t
-> len:size_nat{len > 0}
-> table_len:size_nat{1 < table_len /\ table_len * len <= max_size_t}
-> table:lseq (uint_t t SEC) (table_len * len)
-> i:uint_t t SEC{v i < table_len} ->
Pure (lseq (uint_t t SEC) len)
(requires True)
(ensures fun res ->
let res0 = sub table 0 len in
Math.Lemmas.lemma_mult_le_right len (v i + 1) table_len;
res == Loops.repeati (table_len - 1) (table_select_f len table_len table i) res0 /\
res == sub table (v i * len) len) | val table_select_loop_lemma:
#t:limb_t
-> len:size_nat{len > 0}
-> table_len:size_nat{1 < table_len /\ table_len * len <= max_size_t}
-> table:lseq (uint_t t SEC) (table_len * len)
-> i:uint_t t SEC{v i < table_len} ->
Pure (lseq (uint_t t SEC) len)
(requires True)
(ensures fun res ->
let res0 = sub table 0 len in
Math.Lemmas.lemma_mult_le_right len (v i + 1) table_len;
res == Loops.repeati (table_len - 1) (table_select_f len table_len table i) res0 /\
res == sub table (v i * len) len) | let table_select_loop_lemma #t len table_len table i =
let f = table_select_f len table_len table i in
let res0 = sub table 0 len in
Math.Lemmas.lemma_mult_le_right len (v i + 1) table_len;
Loops.eq_repeati0 (table_len - 1) f res0;
Loops.repeati_inductive (table_len - 1)
(fun j priv ->
priv == Loops.repeati j f res0 /\
priv == (if j >= v i then sub table (v i * len) len else res0))
(fun j priv ->
Loops.unfold_repeati (j + 1) f res0 j;
let res = f j priv in
table_select_f_lemma len table_len table i j priv;
Math.Lemmas.lemma_mult_le_right len (j + 2) table_len;
let res_j = sub table ((j + 1) * len) len in
assert (res == (if v i = j + 1 then res_j else priv));
res) res0 | {
"file_name": "code/bignum/Hacl.Spec.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 105,
"start_col": 0,
"start_line": 88
} | module Hacl.Spec.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
module SB = Hacl.Spec.Bignum.Base
open Hacl.Spec.Bignum.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val table_select_f:
#t:limb_t
-> len:size_nat{len > 0}
-> table_len:size_nat{1 < table_len /\ table_len * len <= max_size_t}
-> table:lseq (uint_t t SEC) (table_len * len)
-> i:uint_t t SEC{v i < table_len}
-> j:size_nat{j < table_len - 1}
-> acc:lseq (uint_t t SEC) len ->
lseq (uint_t t SEC) len
let table_select_f #t len table_len table i j acc =
let c = eq_mask i (SB.size_to_limb (size j +! 1ul)) in
//assert (v c == (if v i = v j + 1 then ones_v a_t else 0));
Math.Lemmas.lemma_mult_le_right len (j + 2) table_len;
let res_j = sub table ((j + 1) * len) len in
let acc = map2 (SB.mask_select c) res_j acc in
acc
val table_select:
#t:limb_t
-> len:size_nat{len > 0}
-> table_len:size_nat{1 < table_len /\ table_len * len <= max_size_t}
-> table:lseq (uint_t t SEC) (table_len * len)
-> i:uint_t t SEC{v i < table_len} ->
lseq (uint_t t SEC) len
let table_select #a_t len table_len table i =
let res = sub table 0 len in
Loops.repeati (table_len - 1) (table_select_f #a_t len table_len table i) res
val table_select_f_lemma:
#t:limb_t
-> len:size_nat{len > 0}
-> table_len:size_nat{1 < table_len /\ table_len * len <= max_size_t}
-> table:lseq (uint_t t SEC) (table_len * len)
-> i:uint_t t SEC{v i < table_len}
-> j:size_nat{j < table_len - 1}
-> acc:lseq (uint_t t SEC) len ->
Lemma (
let res = table_select_f len table_len table i j acc in
Math.Lemmas.lemma_mult_le_right len (j + 2) table_len;
let res_j = sub table ((j + 1) * len) len in
res == (if v i = j + 1 then res_j else acc))
let table_select_f_lemma #t len table_len table i j acc =
let c = eq_mask i (SB.size_to_limb (size (j + 1))) in
assert (v c == (if v i = j + 1 then ones_v t else 0));
Math.Lemmas.lemma_mult_le_right len (j + 2) table_len;
let res_j = sub table ((j + 1) * len) len in
let res = map2 (SB.mask_select c) res_j acc in
SB.lseq_mask_select_lemma res_j acc c
val table_select_loop_lemma:
#t:limb_t
-> len:size_nat{len > 0}
-> table_len:size_nat{1 < table_len /\ table_len * len <= max_size_t}
-> table:lseq (uint_t t SEC) (table_len * len)
-> i:uint_t t SEC{v i < table_len} ->
Pure (lseq (uint_t t SEC) len)
(requires True)
(ensures fun res ->
let res0 = sub table 0 len in
Math.Lemmas.lemma_mult_le_right len (v i + 1) table_len;
res == Loops.repeati (table_len - 1) (table_select_f len table_len table i) res0 /\
res == sub table (v i * len) len) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.PrecompTable.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"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": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.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": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_nat{len > 0} ->
table_len: Lib.IntTypes.size_nat{1 < table_len /\ table_len * len <= Lib.IntTypes.max_size_t} ->
table: Lib.Sequence.lseq (Lib.IntTypes.uint_t t Lib.IntTypes.SEC) (table_len * len) ->
i: Lib.IntTypes.uint_t t Lib.IntTypes.SEC {Lib.IntTypes.v i < table_len}
-> Prims.Pure (Lib.Sequence.lseq (Lib.IntTypes.uint_t t Lib.IntTypes.SEC) len) | Prims.Pure | [] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.v",
"Lib.LoopCombinators.repeati_inductive",
"Prims.l_or",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.nat",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Prims.op_Subtraction",
"Lib.LoopCombinators.repeati",
"Prims.op_GreaterThanOrEqual",
"Lib.Sequence.sub",
"Prims.bool",
"Prims.unit",
"Prims._assert",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.int_t",
"Prims.op_Multiply",
"FStar.Math.Lemmas.lemma_mult_le_right",
"Hacl.Spec.PrecompTable.table_select_f_lemma",
"Lib.LoopCombinators.unfold_repeati",
"Lib.LoopCombinators.eq_repeati0",
"Prims.pow2",
"Hacl.Spec.PrecompTable.table_select_f"
] | [] | false | false | false | false | false | let table_select_loop_lemma #t len table_len table i =
| let f = table_select_f len table_len table i in
let res0 = sub table 0 len in
Math.Lemmas.lemma_mult_le_right len (v i + 1) table_len;
Loops.eq_repeati0 (table_len - 1) f res0;
Loops.repeati_inductive (table_len - 1)
(fun j priv ->
priv == Loops.repeati j f res0 /\
priv == (if j >= v i then sub table (v i * len) len else res0))
(fun j priv ->
Loops.unfold_repeati (j + 1) f res0 j;
let res = f j priv in
table_select_f_lemma len table_len table i j priv;
Math.Lemmas.lemma_mult_le_right len (j + 2) table_len;
let res_j = sub table ((j + 1) * len) len in
assert (res == (if v i = j + 1 then res_j else priv));
res)
res0 | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_stack | val eval_stack (ptr: int) (s: machine_stack) : nat64 | val eval_stack (ptr: int) (s: machine_stack) : nat64 | let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 89,
"start_col": 7,
"start_line": 87
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> s: Vale.X64.Machine_Semantics_s.machine_stack -> Vale.Def.Types_s.nat64 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.get_heap_val64"
] | [] | false | false | false | true | false | let eval_stack (ptr: int) (s: machine_stack) : nat64 =
| let Machine_stack _ mem = s in
get_heap_val64 ptr mem | false |
Hacl.Spec.K256.Field52.Lemmas3.fst | Hacl.Spec.K256.Field52.Lemmas3.fsqr5_lemma | val fsqr5_lemma: a:felem5 -> Lemma
(requires
felem_fits5 a (64,64,64,64,64))
(ensures (let res = fsqr5 a in
as_nat5 res % S.prime == as_nat5 a * as_nat5 a % S.prime /\
felem_fits5 res (1,1,1,1,2))) | val fsqr5_lemma: a:felem5 -> Lemma
(requires
felem_fits5 a (64,64,64,64,64))
(ensures (let res = fsqr5 a in
as_nat5 res % S.prime == as_nat5 a * as_nat5 a % S.prime /\
felem_fits5 res (1,1,1,1,2))) | let fsqr5_lemma a =
let (a0,a1,a2,a3,a4) = a in
let r = u64 0x1000003D10 in
let d0 = mul64_wide (a0 *. u64 2) a3 +. mul64_wide (a1 *. u64 2) a2 in
lemma_four_sqr64_wide a0 a1 a2 a3;
assert (v d0 = v a0 * v a3 + v a1 * v a2 + v a2 * v a1 + v a3 * v a0);
assert (v d0 <= 16384 * (max52 * max52));
let c0 = mul64_wide a4 a4 in
lemma_bound_mul64_wide 64 64 max48 max48 a4 a4;
assert (v c0 = v a4 * v a4);
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 (a4 *. u64 2)
+. mul64_wide (a1 *. u64 2) a3
+. mul64_wide a2 a2 in
lemma_add_five_sqr64_wide 16385 d2 a0 a1 a2 a3 a4;
assert (v d3 == v d2 + v a0 * v a4 + v a1 * v a3 + v a2 * v a2 + v a3 * v a1 + v a4 * v a0);
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 a0 in
lemma_bound_mul64_wide 64 64 max52 max52 a0 a0;
assert (v c2 = v a0 * v a0);
assert (v c2 <= 4096 * (max52 * max52));
let d6 = d5
+. mul64_wide a1 (a4 *. u64 2)
+. mul64_wide (a2 *. u64 2) a3 in
lemma_add_four_sqr64_wide 12802 d5 a1 a2 a3 a4;
assert (v d6 == v d5 + v a1 * v a4 + v a2 * v a3 + v a3 * v a2 + v a4 * v a1);
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 *. u64 2) a1 in
lemma_add_two_sqr64_wide52 4097 c4 a0 a1;
assert (v c5 = v c4 + v a0 * v a1 + v a1 * v a0);
assert (v c5 <= 8193 * (max52 * max52));
let d8 = d7
+. mul64_wide a2 (a4 *. u64 2)
+. mul64_wide a3 a3 in
lemma_add_three_sqr64_wide 8705 d7 a2 a3 a4;
assert (v d8 = v d7 + v a2 * v a4 + v a3 * v a3 + v a4 * v a2);
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 *. u64 2) a2
+. mul64_wide a1 a1 in
lemma_add_three_sqr64_wide52 8194 c7 a0 a1 a2;
assert (v c8 == v c7 + v a0 * v a2 + v a1 * v a1 + v a2 * v a0);
assert (v c8 <= 12289 * (max52 * max52));
let d10 = d9
+. mul64_wide a3 (a4 *. u64 2) in
lemma_add_two_sqr64_wide 8193 d9 a3 a4;
assert (v d10 == v d9 + v a3 * v a4 + v a4 * v a3);
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 == fsqr5 a);
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 a0) (v a1) (v a2) (v a3) (v a4) | {
"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": 392,
"start_col": 0,
"start_line": 220
} | 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)))
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)
/// squaring
val fsqr5_lemma: a:felem5 -> Lemma
(requires
felem_fits5 a (64,64,64,64,64))
(ensures (let res = fsqr5 a in
as_nat5 res % S.prime == as_nat5 a * as_nat5 a % 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
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.K256.Field52.Definitions.felem_fits5 a (64, 64, 64, 64, 64))
(ensures
(let res = Hacl.Spec.K256.Field52.fsqr5 a 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 a %
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.fsqr5",
"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_sqr64_wide",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_three_sqr64_wide52",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_add_mul64_wide_r_mask52",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_three_sqr64_wide",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_add_two_sqr64_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_sqr64_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_sqr64_wide",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_bound_c0",
"Hacl.Spec.K256.Field52.Definitions.max48",
"Hacl.Spec.K256.Field52.Lemmas5.lemma_four_sqr64_wide",
"Lib.IntTypes.range"
] | [] | false | false | true | false | false | let fsqr5_lemma a =
| let a0, a1, a2, a3, a4 = a in
let r = u64 0x1000003D10 in
let d0 = mul64_wide (a0 *. u64 2) a3 +. mul64_wide (a1 *. u64 2) a2 in
lemma_four_sqr64_wide a0 a1 a2 a3;
assert (v d0 = v a0 * v a3 + v a1 * v a2 + v a2 * v a1 + v a3 * v a0);
assert (v d0 <= 16384 * (max52 * max52));
let c0 = mul64_wide a4 a4 in
lemma_bound_mul64_wide 64 64 max48 max48 a4 a4;
assert (v c0 = v a4 * v a4);
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 (a4 *. u64 2) +. mul64_wide (a1 *. u64 2) a3 +. mul64_wide a2 a2 in
lemma_add_five_sqr64_wide 16385 d2 a0 a1 a2 a3 a4;
assert (v d3 == v d2 + v a0 * v a4 + v a1 * v a3 + v a2 * v a2 + v a3 * v a1 + v a4 * v a0);
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 a0 in
lemma_bound_mul64_wide 64 64 max52 max52 a0 a0;
assert (v c2 = v a0 * v a0);
assert (v c2 <= 4096 * (max52 * max52));
let d6 = d5 +. mul64_wide a1 (a4 *. u64 2) +. mul64_wide (a2 *. u64 2) a3 in
lemma_add_four_sqr64_wide 12802 d5 a1 a2 a3 a4;
assert (v d6 == v d5 + v a1 * v a4 + v a2 * v a3 + v a3 * v a2 + v a4 * v a1);
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 *. u64 2) a1 in
lemma_add_two_sqr64_wide52 4097 c4 a0 a1;
assert (v c5 = v c4 + v a0 * v a1 + v a1 * v a0);
assert (v c5 <= 8193 * (max52 * max52));
let d8 = d7 +. mul64_wide a2 (a4 *. u64 2) +. mul64_wide a3 a3 in
lemma_add_three_sqr64_wide 8705 d7 a2 a3 a4;
assert (v d8 = v d7 + v a2 * v a4 + v a3 * v a3 + v a4 * v a2);
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 *. u64 2) a2 +. mul64_wide a1 a1 in
lemma_add_three_sqr64_wide52 8194 c7 a0 a1 a2;
assert (v c8 == v c7 + v a0 * v a2 + v a1 * v a1 + v a2 * v a0);
assert (v c8 <= 12289 * (max52 * max52));
let d10 = d9 +. mul64_wide a3 (a4 *. u64 2) in
lemma_add_two_sqr64_wide 8193 d9 a3 a4;
assert (v d10 == v d9 + v a3 * v a4 + v a4 * v a3);
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 == fsqr5 a);
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 a0) (v a1) (v a2) (v a3) (v a4) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_stack128_and_taint | val update_stack128_and_taint (ptr: int) (v: quad32) (s: machine_state) (t: taint) : machine_state | val update_stack128_and_taint (ptr: int) (v: quad32) (s: machine_state) (t: taint) : machine_state | let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
} | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 243,
"start_col": 0,
"start_line": 238
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
ptr: Prims.int ->
v: Vale.Def.Types_s.quad32 ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"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.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.update_stack128'",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.update_n",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"Vale.X64.Machine_Semantics_s.machine_stack"
] | [] | false | false | false | true | false | let update_stack128_and_taint (ptr: int) (v: quad32) (s: machine_state) (t: taint) : machine_state =
| let Machine_stack init_rsp mem = s.ms_stack in
{
s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
} | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_stack128' | val update_stack128' (ptr: int) (v: quad32) (s: machine_stack) : machine_stack | val update_stack128' (ptr: int) (v: quad32) (s: machine_stack) : machine_stack | let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 229,
"start_col": 0,
"start_line": 226
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> s: Vale.X64.Machine_Semantics_s.machine_stack
-> Vale.X64.Machine_Semantics_s.machine_stack | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Vale.X64.Machine_Semantics_s.Machine_stack",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap128"
] | [] | false | false | false | true | false | let update_stack128' (ptr: int) (v: quad32) (s: machine_stack) : machine_stack =
| let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem | false |
Pulse.Elaborate.fst | Pulse.Elaborate.elab_ln | val elab_ln (t:term) (i:int)
: Lemma (requires ln' t i)
(ensures RT.ln' (elab_term t) i) | val elab_ln (t:term) (i:int)
: Lemma (requires ln' t i)
(ensures RT.ln' (elab_term t) i) | let rec elab_ln t i =
match t.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_ln p i
| Tm_Pure t -> elab_ln t i
| Tm_AddInv l r
| Tm_Star l r ->
elab_ln l i;
elab_ln r i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_ln t.binder_ty i;
elab_ln body (i + 1)
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown
| Tm_FStar _ -> () | {
"file_name": "lib/steel/pulse/Pulse.Elaborate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 165,
"start_col": 0,
"start_line": 148
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Elaborate
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Elaborate.Core
// let rec elab_term_bv_sort (t:term)
// : Lemma
// (ensures
// (R.Tv_Var? (R.inspect_ln (elab_term t)) \/
// R.Tv_BVar? (R.inspect_ln (elab_term t))) ==>
// (match R.inspect_ln (elab_term t) with
// | R.Tv_Var bv
// | R.Tv_BVar bv ->
// let vv = R.inspect_bv bv in
// vv.bv_sort == RT.tun))
// = admit()
#push-options "--fuel 10 --ifuel 10 --z3rlimit_factor 30 --query_stats --z3cliopt 'smt.qi.eager_threshold=100'"
let rec elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
// | Tm_PureApp e1 _ e2 ->
// elab_open_commute' e1 v n;
// elab_open_commute' e2 v n
| Tm_Inv p ->
elab_open_commute' p v n
| Tm_Pure p ->
elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> ()
let elab_comp_open_commute' (c:comp) (v:term) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.DT n (elab_term v) ] ==
elab_comp (open_comp' c v n))
= match c with
| C_Tot t -> elab_open_commute' t v n
| C_ST s
| C_STGhost s ->
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_open_commute' inames v n;
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
let rec elab_close_commute' (e:term)
(v:var)
(n:index)
: Lemma (ensures (
RT.subst_term (elab_term e) [ RT.ND v n ] ==
elab_term (close_term' e v n)))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
| Tm_Inv p ->
elab_close_commute' p v n
| Tm_Pure p ->
elab_close_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_close_commute' e1 v n;
elab_close_commute' e2 v n
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_close_commute' t.binder_ty v n;
elab_close_commute' body v (n + 1)
| Tm_FStar _ -> ()
let elab_comp_close_commute' (c:comp) (v:var) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.ND v n ] ==
elab_comp (close_comp' c v n))
(decreases c)
= match c with
| C_Tot t -> elab_close_commute' t v n
| C_ST s
| C_STGhost s ->
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_close_commute' inames v n;
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
let elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x)
= RT.open_term_spec (elab_term t) x;
elab_open_commute' t (null_var x) 0
let elab_comp_close_commute (c:comp) (x:var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x)
= RT.close_term_spec (elab_comp c) x;
elab_comp_close_commute' c x 0
let elab_comp_open_commute (c:comp) (x:term)
: Lemma (elab_comp (open_comp_with c x) == RT.open_with (elab_comp c) (elab_term x))
= RT.open_with_spec (elab_comp c) (elab_term x);
elab_comp_open_commute' c x 0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Elaborate.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Naming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"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": 10,
"initial_ifuel": 10,
"max_fuel": 10,
"max_ifuel": 10,
"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.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 30,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> i: Prims.int
-> FStar.Pervasives.Lemma (requires Pulse.Syntax.Naming.ln' t i)
(ensures FStar.Reflection.Typing.ln' (Pulse.Elaborate.Pure.elab_term t) i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Pulse.Syntax.Base.term",
"Prims.int",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Elaborate.elab_ln",
"Prims.unit",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Prims.op_Addition",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.host_term"
] | [
"recursion"
] | false | false | true | false | false | let rec elab_ln t i =
| match t.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_ln p i
| Tm_Pure t -> elab_ln t i
| Tm_AddInv l r
| Tm_Star l r ->
elab_ln l i;
elab_ln r i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_ln t.binder_ty i;
elab_ln body (i + 1)
| Tm_VProp | Tm_Inames | Tm_EmpInames | Tm_Unknown | Tm_FStar _ -> () | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_stack64' | val update_stack64' (ptr: int) (v: nat64) (s: machine_stack) : machine_stack | val update_stack64' (ptr: int) (v: nat64) (s: machine_stack) : machine_stack | let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 223,
"start_col": 0,
"start_line": 220
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> s: Vale.X64.Machine_Semantics_s.machine_stack
-> Vale.X64.Machine_Semantics_s.machine_stack | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Vale.X64.Machine_Semantics_s.Machine_stack",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap64"
] | [] | false | false | false | true | false | let update_stack64' (ptr: int) (v: nat64) (s: machine_stack) : machine_stack =
| let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_src_stack64 | val valid_src_stack64 (ptr: int) (st: machine_stack) : bool | val valid_src_stack64 (ptr: int) (st: machine_stack) : bool | let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 248,
"start_col": 0,
"start_line": 246
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> st: Vale.X64.Machine_Semantics_s.machine_stack -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_src_stack64 (ptr: int) (st: machine_stack) : bool =
| let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_stack_and_taint | val update_stack_and_taint (ptr: int) (v: nat64) (s: machine_state) (t: taint) : machine_state | val update_stack_and_taint (ptr: int) (v: nat64) (s: machine_state) (t: taint) : machine_state | let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
} | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 236,
"start_col": 0,
"start_line": 231
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
ptr: Prims.int ->
v: Vale.Def.Types_s.nat64 ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Arch.HeapTypes_s.taint",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"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.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.update_stack64'",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.update_n",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"Vale.X64.Machine_Semantics_s.machine_stack"
] | [] | false | false | false | true | false | let update_stack_and_taint (ptr: int) (v: nat64) (s: machine_state) (t: taint) : machine_state =
| let Machine_stack init_rsp mem = s.ms_stack in
{
s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t
} | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_src_stack128 | val valid_src_stack128 (ptr: int) (st: machine_stack) : bool | val valid_src_stack128 (ptr: int) (st: machine_stack) : bool | let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 253,
"start_col": 0,
"start_line": 251
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> st: Vale.X64.Machine_Semantics_s.machine_stack -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_src_stack128 (ptr: int) (st: machine_stack) : bool =
| let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem | false |
Hacl.K256.PrecompTable.fst | Hacl.K256.PrecompTable.precomp_basepoint_table_w5 | val precomp_basepoint_table_w5:
x:glbuffer uint64 480ul{witnessed x precomp_basepoint_table_lseq_w5 /\ recallable x} | val precomp_basepoint_table_w5:
x:glbuffer uint64 480ul{witnessed x precomp_basepoint_table_lseq_w5 /\ recallable x} | let precomp_basepoint_table_w5:
x:glbuffer uint64 480ul{witnessed x precomp_basepoint_table_lseq_w5 /\ recallable x} =
createL_global precomp_basepoint_table_list_w5 | {
"file_name": "code/k256/Hacl.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 295,
"start_col": 0,
"start_line": 293
} | module Hacl.K256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.K256.PrecompTable
module S = Spec.K256
module SL = Spec.K256.Lemmas
open Hacl.Impl.K256.Point
include Hacl.Impl.K256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x46ec0aa60b0b98c37b29371784676ad967b7beb1a941ddb6fbbff95b44cb788b in
[@inline_let]
let rY : S.felem = 0x6b946755bbc6b677576579c990a1ccf14a710545251a1428fabbf02f40268e63 in
[@inline_let]
let rZ : S.felem = 0x3c114b2ac17c199ec9eba9f7cc64dc459ca2e53f5bbead2b4e618b318ffcc00e in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_k256_concrete_ops S.g 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops S.g 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64);
let rX : S.felem = 0x46ec0aa60b0b98c37b29371784676ad967b7beb1a941ddb6fbbff95b44cb788b in
let rY : S.felem = 0x6b946755bbc6b677576579c990a1ccf14a710545251a1428fabbf02f40268e63 in
let rZ : S.felem = 0x3c114b2ac17c199ec9eba9f7cc64dc459ca2e53f5bbead2b4e618b318ffcc00e in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x98299efbc8e459915404ae015b48cac3b929e0158665f3c7fa5489fbd25c4297 in
[@inline_let]
let rY : S.felem = 0xf1e5cbc9579e7d11a31681e947c2959ae0298a006d1c06ab1ad93d6716ea50cc in
[@inline_let]
let rZ : S.felem = 0x5c53ffe15001674a2eacb60c9327a8b0ddbd93a0fa6d90309de6cc124133938b in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x98299efbc8e459915404ae015b48cac3b929e0158665f3c7fa5489fbd25c4297 in
let rY : S.felem = 0xf1e5cbc9579e7d11a31681e947c2959ae0298a006d1c06ab1ad93d6716ea50cc in
let rZ : S.felem = 0x5c53ffe15001674a2eacb60c9327a8b0ddbd93a0fa6d90309de6cc124133938b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xbd382b67d20492b1480ca58a6d7d617ba413a9bc7c2f1cff51301ef960fb245c in
[@inline_let]
let rY : S.felem = 0x0b232afcf692673aa714357c524c07867a64ea3b9dfab53f0e74622159e86b0d in
[@inline_let]
let rZ : S.felem = 0x028a1380449aede5df8219420b458d464a6a4773ac91e8305237878cef1cffa6 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xbd382b67d20492b1480ca58a6d7d617ba413a9bc7c2f1cff51301ef960fb245c in
let rY : S.felem = 0x0b232afcf692673aa714357c524c07867a64ea3b9dfab53f0e74622159e86b0d in
let rZ : S.felem = 0x028a1380449aede5df8219420b458d464a6a4773ac91e8305237878cef1cffa6 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 15 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 15 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list
let proj_g_pow2_192_lseq : LSeq.lseq uint64 15 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list
val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff)
let proj_g_pow2_64_lemma () =
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_k256_concrete_ops S.g
val proj_g_pow2_128_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff)
let proj_g_pow2_128_lemma () =
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_128_lemma S.mk_k256_concrete_ops S.g
val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff)
let proj_g_pow2_192_lemma () =
lemma_proj_g_pow2_192_eval ();
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_192_lemma S.mk_k256_concrete_ops S.g
let proj_g_pow2_64_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
proj_g_pow2_64_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_64
let proj_g_pow2_128_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
proj_g_pow2_128_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_128
let proj_g_pow2_192_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
proj_g_pow2_192_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_192
let mk_proj_g_pow2_64 () =
createL proj_g_pow2_64_list
let mk_proj_g_pow2_128 () =
createL proj_g_pow2_128_list
let mk_proj_g_pow2_192 () =
createL proj_g_pow2_192_list
//----------------
/// window size = 4; precomputed table = [[0]G, [1]G, ..., [15]G]
inline_for_extraction noextract
let precomp_basepoint_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} =
normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15)
let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 240 =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15);
Seq.seq_of_list precomp_basepoint_table_list_w4
let precomp_basepoint_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15);
SPT.precomp_base_table_lemma mk_k256_precomp_base_table S.g 16 precomp_basepoint_table_lseq_w4
let precomp_basepoint_table_w4:
x:glbuffer uint64 240ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} =
createL_global precomp_basepoint_table_list_w4
/// window size = 4; precomputed table = [[0]([pow2 64]G), [1]([pow2 64]G), ..., [15]([pow2 64]G)]
inline_for_extraction noextract
let precomp_g_pow2_64_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} =
normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15)
let precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 240 =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15);
Seq.seq_of_list precomp_g_pow2_64_table_list_w4
let precomp_g_pow2_64_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15);
SPT.precomp_base_table_lemma mk_k256_precomp_base_table
proj_g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4;
proj_g_pow2_64_lemma ()
let precomp_g_pow2_64_table_w4:
x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_64_table_lseq_w4 /\ recallable x} =
createL_global precomp_g_pow2_64_table_list_w4
/// window size = 4; precomputed table = [[0]([pow2 128]G), [1]([pow2 128]G),...,[15]([pow2 128]G)]
inline_for_extraction noextract
let precomp_g_pow2_128_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} =
normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_128 15)
let precomp_g_pow2_128_table_lseq_w4 : LSeq.lseq uint64 240 =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_128 15);
Seq.seq_of_list precomp_g_pow2_128_table_list_w4
let precomp_g_pow2_128_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_128 15);
SPT.precomp_base_table_lemma mk_k256_precomp_base_table
proj_g_pow2_128 16 precomp_g_pow2_64_table_lseq_w4;
proj_g_pow2_128_lemma ()
let precomp_g_pow2_128_table_w4:
x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_128_table_lseq_w4 /\ recallable x} =
createL_global precomp_g_pow2_128_table_list_w4
/// window size = 4; precomputed table = [[0]([pow2 192]G), [1]([pow2 192]G),...,[15]([pow2 192]G)]
inline_for_extraction noextract
let precomp_g_pow2_192_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} =
normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_192 15)
let precomp_g_pow2_192_table_lseq_w4 : LSeq.lseq uint64 240 =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_192 15);
Seq.seq_of_list precomp_g_pow2_192_table_list_w4
let precomp_g_pow2_192_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_192 15);
SPT.precomp_base_table_lemma mk_k256_precomp_base_table
proj_g_pow2_192 16 precomp_g_pow2_64_table_lseq_w4;
proj_g_pow2_192_lemma ()
let precomp_g_pow2_192_table_w4:
x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_192_table_lseq_w4 /\ recallable x} =
createL_global precomp_g_pow2_192_table_list_w4
/// window size = 5; precomputed table = [[0]G, [1]G, ..., [31]G]
inline_for_extraction noextract
let precomp_basepoint_table_list_w5: x:list uint64{FStar.List.Tot.length x = 480} =
normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 31)
let precomp_basepoint_table_lseq_w5 : LSeq.lseq uint64 480 =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 31);
Seq.seq_of_list precomp_basepoint_table_list_w5
let precomp_basepoint_table_lemma_w5 () =
normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 31);
SPT.precomp_base_table_lemma mk_k256_precomp_base_table S.g 32 precomp_basepoint_table_lseq_w5 | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.PrecompTable.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"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.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x:
Lib.Buffer.glbuffer Lib.IntTypes.uint64 480ul
{ Lib.Buffer.witnessed x Hacl.K256.PrecompTable.precomp_basepoint_table_lseq_w5 /\
Lib.Buffer.recallable x } | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.createL_global",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Hacl.K256.PrecompTable.precomp_basepoint_table_list_w5",
"Lib.Buffer.glbuffer",
"Lib.IntTypes.size",
"FStar.Pervasives.normalize_term",
"Lib.IntTypes.size_nat",
"FStar.List.Tot.Base.length",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Lib.Buffer.witnessed",
"Hacl.K256.PrecompTable.precomp_basepoint_table_lseq_w5",
"Lib.Buffer.recallable",
"Lib.Buffer.CONST"
] | [] | false | false | false | false | false | let precomp_basepoint_table_w5:x:
glbuffer uint64 480ul {witnessed x precomp_basepoint_table_lseq_w5 /\ recallable x} =
| createL_global precomp_basepoint_table_list_w5 | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_ocmp_opaque | val valid_ocmp_opaque (c: ocmp) (s: machine_state) : bool | val valid_ocmp_opaque (c: ocmp) (s: machine_state) : bool | let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 293,
"start_col": 0,
"start_line": 293
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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.ocmp -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.valid_ocmp",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_ocmp_opaque (c: ocmp) (s: machine_state) : bool =
| valid_ocmp c s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_dst_stack64 | val valid_dst_stack64 (rsp: nat64) (ptr: int) (st: machine_stack) : bool | val valid_dst_stack64 (rsp: nat64) (ptr: int) (st: machine_stack) : bool | let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 299,
"start_col": 0,
"start_line": 296
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | rsp: Vale.Def.Types_s.nat64 -> ptr: Prims.int -> st: Vale.X64.Machine_Semantics_s.machine_stack
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.nat64",
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_dst_stack64 (rsp: nat64) (ptr: int) (st: machine_stack) : bool =
| let Machine_stack init_rsp mem = st in
ptr >= rsp && ptr + 8 <= init_rsp | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_dst_stack128 | val valid_dst_stack128 (rsp: nat64) (ptr: int) (st: machine_stack) : bool | val valid_dst_stack128 (rsp: nat64) (ptr: int) (st: machine_stack) : bool | let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 305,
"start_col": 0,
"start_line": 302
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | rsp: Vale.Def.Types_s.nat64 -> ptr: Prims.int -> st: Vale.X64.Machine_Semantics_s.machine_stack
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.nat64",
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_dst_stack128 (rsp: nat64) (ptr: int) (st: machine_stack) : bool =
| let Machine_stack init_rsp mem = st in
ptr >= rsp && ptr + 16 <= init_rsp | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_reg_64 | val eval_reg_64 (r: reg_64) (s: machine_state) : nat64 | val eval_reg_64 (r: reg_64) (s: machine_state) : nat64 | let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 79,
"start_col": 7,
"start_line": 79
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | r: Vale.X64.Machine_s.reg_64 -> s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.Def.Types_s.nat64 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.eval_reg",
"Vale.X64.Machine_s.Reg",
"Vale.Def.Types_s.nat64"
] | [] | false | false | false | true | false | let eval_reg_64 (r: reg_64) (s: machine_state) : nat64 =
| eval_reg (Reg 0 r) s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_operand64_preserve_flags' | val update_operand64_preserve_flags' (o: operand64) (v: nat64) (s: machine_state) : machine_state | val update_operand64_preserve_flags' (o: operand64) (v: nat64) (s: machine_state) : machine_state | let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 329,
"start_col": 0,
"start_line": 328
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
o: Vale.X64.Machine_s.operand64 ->
v: Vale.Def.Types_s.nat64 ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.update_operand64_preserve_flags''"
] | [] | false | false | false | true | false | let update_operand64_preserve_flags' (o: operand64) (v: nat64) (s: machine_state) : machine_state =
| update_operand64_preserve_flags'' o v s s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_n | val update_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint)
: Tot
(m:
memTaint_t
{ (forall i. {:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[ i ] == t) /\
((i < addr \/ i >= addr + n) ==> m.[ i ] == memTaint.[ i ])) }) (decreases n) | val update_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint)
: Tot
(m:
memTaint_t
{ (forall i. {:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[ i ] == t) /\
((i < addr \/ i >= addr + n) ==> m.[ i ] == memTaint.[ i ])) }) (decreases n) | let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 165,
"start_col": 0,
"start_line": 157
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
addr: Prims.int ->
n: Prims.nat ->
memTaint: Vale.Arch.HeapTypes_s.memTaint_t ->
t: Vale.Arch.HeapTypes_s.taint
-> Prims.Tot
(m:
Vale.Arch.HeapTypes_s.memTaint_t
{ forall (i: Prims.int). {:pattern FStar.Map.sel m i}
(i >= addr /\ i < addr + n ==> m.[ i ] == t) /\
(i < addr \/ i >= addr + n ==> m.[ i ] == memTaint.[ i ]) }) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.int",
"Prims.nat",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Arch.HeapTypes_s.taint",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.update_n",
"Prims.op_Addition",
"Prims.op_Subtraction",
"Vale.X64.Machine_Semantics_s.op_String_Assignment",
"Prims.l_Forall",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.eq2",
"Vale.X64.Machine_Semantics_s.op_String_Access",
"Prims.l_or",
"FStar.Map.sel"
] | [
"recursion"
] | false | false | false | false | false | let rec update_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint)
: Tot
(m:
memTaint_t
{ (forall i. {:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[ i ] == t) /\
((i < addr \/ i >= addr + n) ==> m.[ i ] == memTaint.[ i ])) }) (decreases n) =
| if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[ addr ] <- t) t | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_reg' | val update_reg' (r: reg) (v: t_reg r) (s: machine_state) : machine_state | val update_reg' (r: reg) (v: t_reg r) (s: machine_state) : machine_state | let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')} | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 109,
"end_line": 127,
"start_col": 0,
"start_line": 126
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
r: Vale.X64.Machine_s.reg ->
v: Vale.X64.Machine_s.t_reg r ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg",
"Vale.X64.Machine_s.t_reg",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"FStar.FunctionalExtensionality.on_dom",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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"
] | [] | false | false | false | false | false | let update_reg' (r: reg) (v: t_reg r) (s: machine_state) : machine_state =
| {
s with
ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')
} | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.get_snd_ocmp | val get_snd_ocmp : o: Vale.X64.Machine_Semantics_s.ocmp
-> o2:
Vale.X64.Machine_s.operand64
{ Prims.op_Negation (OMem? o2 || OStack? o2) \/ Prims.op_Negation (OMem? o2 || OStack? o2) \/
Prims.op_Negation (OMem? o2 || OStack? o2) \/ Prims.op_Negation (OMem? o2 || OStack? o2) \/
Prims.op_Negation (OMem? o2 || OStack? o2) \/ Prims.op_Negation (OMem? o2 || OStack? o2) } | let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2 | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 76,
"start_col": 0,
"start_line": 75
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_Semantics_s.ocmp
-> o2:
Vale.X64.Machine_s.operand64
{ Prims.op_Negation (OMem? o2 || OStack? o2) \/ Prims.op_Negation (OMem? o2 || OStack? o2) \/
Prims.op_Negation (OMem? o2 || OStack? o2) \/ Prims.op_Negation (OMem? o2 || OStack? o2) \/
Prims.op_Negation (OMem? o2 || OStack? o2) \/ Prims.op_Negation (OMem? o2 || OStack? o2) } | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"Prims.l_or"
] | [] | false | false | false | false | false | let get_snd_ocmp (o: ocmp) =
| match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2 | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_mem128_and_taint | val update_mem128_and_taint (ptr: int) (v: quad32) (s: machine_state) (t: taint) : machine_state | val update_mem128_and_taint (ptr: int) (v: quad32) (s: machine_state) (t: taint) : machine_state | let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 217,
"start_col": 0,
"start_line": 210
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
ptr: Prims.int ->
v: Vale.Def.Types_s.quad32 ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"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.__proj__Mkmachine_state__item__ms_flags",
"Vale.Arch.Heap.heap_upd",
"Vale.Arch.MachineHeap_s.update_heap128",
"Vale.X64.Machine_Semantics_s.update_n",
"Vale.Arch.Heap.heap_taint",
"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",
"Prims.bool"
] | [] | false | false | false | true | false | let update_mem128_and_taint (ptr: int) (v: quad32) (s: machine_state) (t: taint) : machine_state =
| if valid_addr128 ptr (heap_get s.ms_heap)
then
{
s with
ms_heap
=
heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.havoc_flags | val havoc_flags:flags_t | val havoc_flags:flags_t | let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 342,
"start_col": 0,
"start_line": 342
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Vale.X64.Machine_Semantics_s.flags_t | Prims.Tot | [
"total"
] | [] | [
"FStar.FunctionalExtensionality.on_dom",
"Vale.X64.Machine_s.flag",
"Vale.X64.Machine_Semantics_s.flag_val_t",
"Vale.X64.Machine_Semantics_s.flags_none"
] | [] | false | false | false | true | false | let havoc_flags:flags_t =
| FStar.FunctionalExtensionality.on_dom flag flags_none | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.flags_none | val flags_none (f: flag) : flag_val_t | val flags_none (f: flag) : flag_val_t | let flags_none (f:flag) : flag_val_t = None | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 341,
"start_col": 0,
"start_line": 341
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | f: Vale.X64.Machine_s.flag -> Vale.X64.Machine_Semantics_s.flag_val_t | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.flag",
"FStar.Pervasives.Native.None",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.flag_val_t"
] | [] | false | false | false | true | false | let flags_none (f: flag) : flag_val_t =
| None | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_reg_xmm | val eval_reg_xmm (r: reg_xmm) (s: machine_state) : quad32 | val eval_reg_xmm (r: reg_xmm) (s: machine_state) : quad32 | let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 85,
"end_line": 80,
"start_col": 7,
"start_line": 80
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | r: Vale.X64.Machine_s.reg_xmm -> s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.eval_reg",
"Vale.X64.Machine_s.Reg",
"Vale.Def.Types_s.quad32"
] | [] | false | false | false | true | false | let eval_reg_xmm (r: reg_xmm) (s: machine_state) : quad32 =
| eval_reg (Reg 1 r) s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_mov128_op | val eval_mov128_op (o: operand128) (s: machine_state) : quad32 | val eval_mov128_op (o: operand128) (s: machine_state) : quad32 | let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 113,
"start_col": 0,
"start_line": 108
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_s.operand128 -> s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Machine_Semantics_s.eval_reg_xmm",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_Semantics_s.eval_mem128",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.X64.Machine_Semantics_s.eval_stack128",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.Def.Types_s.quad32"
] | [] | false | false | false | true | false | let eval_mov128_op (o: operand128) (s: machine_state) : quad32 =
| match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_reg_64' | val update_reg_64' (r: reg_64) (v: nat64) (s: machine_state) : machine_state | val update_reg_64' (r: reg_64) (v: nat64) (s: machine_state) : machine_state | let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 130,
"start_col": 0,
"start_line": 129
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
r: Vale.X64.Machine_s.reg_64 ->
v: Vale.Def.Types_s.nat64 ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg_64",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.update_reg'",
"Vale.X64.Machine_s.Reg"
] | [] | false | false | false | true | false | let update_reg_64' (r: reg_64) (v: nat64) (s: machine_state) : machine_state =
| update_reg' (Reg 0 r) v s | false |
Pulse.Elaborate.fst | Pulse.Elaborate.elab_ln_comp | val elab_ln_comp (c:comp) (i:int)
: Lemma (requires ln_c' c i) (ensures RT.ln' (elab_comp c) i) | val elab_ln_comp (c:comp) (i:int)
: Lemma (requires ln_c' c i) (ensures RT.ln' (elab_comp c) i) | let elab_ln_comp (c:comp) (i:int)
: Lemma (requires ln_c' c i)
(ensures RT.ln' (elab_comp c) i) =
match c with
| C_Tot t -> elab_ln t i
| C_ST st
| C_STGhost st ->
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1)
| C_STAtomic inames _ st ->
elab_ln inames i;
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1) | {
"file_name": "lib/steel/pulse/Pulse.Elaborate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 27,
"end_line": 182,
"start_col": 0,
"start_line": 167
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Elaborate
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Elaborate.Core
// let rec elab_term_bv_sort (t:term)
// : Lemma
// (ensures
// (R.Tv_Var? (R.inspect_ln (elab_term t)) \/
// R.Tv_BVar? (R.inspect_ln (elab_term t))) ==>
// (match R.inspect_ln (elab_term t) with
// | R.Tv_Var bv
// | R.Tv_BVar bv ->
// let vv = R.inspect_bv bv in
// vv.bv_sort == RT.tun))
// = admit()
#push-options "--fuel 10 --ifuel 10 --z3rlimit_factor 30 --query_stats --z3cliopt 'smt.qi.eager_threshold=100'"
let rec elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
// | Tm_PureApp e1 _ e2 ->
// elab_open_commute' e1 v n;
// elab_open_commute' e2 v n
| Tm_Inv p ->
elab_open_commute' p v n
| Tm_Pure p ->
elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> ()
let elab_comp_open_commute' (c:comp) (v:term) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.DT n (elab_term v) ] ==
elab_comp (open_comp' c v n))
= match c with
| C_Tot t -> elab_open_commute' t v n
| C_ST s
| C_STGhost s ->
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_open_commute' inames v n;
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
let rec elab_close_commute' (e:term)
(v:var)
(n:index)
: Lemma (ensures (
RT.subst_term (elab_term e) [ RT.ND v n ] ==
elab_term (close_term' e v n)))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
| Tm_Inv p ->
elab_close_commute' p v n
| Tm_Pure p ->
elab_close_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_close_commute' e1 v n;
elab_close_commute' e2 v n
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_close_commute' t.binder_ty v n;
elab_close_commute' body v (n + 1)
| Tm_FStar _ -> ()
let elab_comp_close_commute' (c:comp) (v:var) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.ND v n ] ==
elab_comp (close_comp' c v n))
(decreases c)
= match c with
| C_Tot t -> elab_close_commute' t v n
| C_ST s
| C_STGhost s ->
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_close_commute' inames v n;
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
let elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x)
= RT.open_term_spec (elab_term t) x;
elab_open_commute' t (null_var x) 0
let elab_comp_close_commute (c:comp) (x:var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x)
= RT.close_term_spec (elab_comp c) x;
elab_comp_close_commute' c x 0
let elab_comp_open_commute (c:comp) (x:term)
: Lemma (elab_comp (open_comp_with c x) == RT.open_with (elab_comp c) (elab_term x))
= RT.open_with_spec (elab_comp c) (elab_term x);
elab_comp_open_commute' c x 0
let rec elab_ln t i =
match t.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_ln p i
| Tm_Pure t -> elab_ln t i
| Tm_AddInv l r
| Tm_Star l r ->
elab_ln l i;
elab_ln r i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_ln t.binder_ty i;
elab_ln body (i + 1)
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown
| Tm_FStar _ -> () | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Elaborate.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Naming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"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": 10,
"initial_ifuel": 10,
"max_fuel": 10,
"max_ifuel": 10,
"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.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 30,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Pulse.Syntax.Base.comp -> i: Prims.int
-> FStar.Pervasives.Lemma (requires Pulse.Syntax.Naming.ln_c' c i)
(ensures FStar.Reflection.Typing.ln' (Pulse.Elaborate.Pure.elab_comp c) i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Pulse.Syntax.Base.comp",
"Prims.int",
"Pulse.Syntax.Base.term",
"Pulse.Elaborate.elab_ln",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Prims.op_Addition",
"Prims.unit",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.observability",
"Prims.b2t",
"Pulse.Syntax.Naming.ln_c'",
"Prims.squash",
"FStar.Reflection.Typing.ln'",
"Pulse.Elaborate.Pure.elab_comp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let elab_ln_comp (c: comp) (i: int) : Lemma (requires ln_c' c i) (ensures RT.ln' (elab_comp c) i) =
| match c with
| C_Tot t -> elab_ln t i
| C_ST st
| C_STGhost st ->
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1)
| C_STAtomic inames _ st ->
elab_ln inames i;
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_reg_xmm' | val update_reg_xmm' (r: reg_xmm) (v: quad32) (s: machine_state) : machine_state | val update_reg_xmm' (r: reg_xmm) (v: quad32) (s: machine_state) : machine_state | let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 133,
"start_col": 0,
"start_line": 132
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
r: Vale.X64.Machine_s.reg_xmm ->
v: Vale.Def.Types_s.quad32 ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg_xmm",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.update_reg'",
"Vale.X64.Machine_s.Reg"
] | [] | false | false | false | true | false | let update_reg_xmm' (r: reg_xmm) (v: quad32) (s: machine_state) : machine_state =
| update_reg' (Reg 1 r) v s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_operand128_preserve_flags' | val update_operand128_preserve_flags' (o: operand128) (v: quad32) (s: machine_state) : machine_state | val update_operand128_preserve_flags' (o: operand128) (v: quad32) (s: machine_state) : machine_state | let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 339,
"start_col": 0,
"start_line": 338
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
o: Vale.X64.Machine_s.operand128 ->
v: Vale.Def.Types_s.quad32 ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand128",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.update_operand128_preserve_flags''"
] | [] | false | false | false | true | false | let update_operand128_preserve_flags' (o: operand128) (v: quad32) (s: machine_state) : machine_state =
| update_operand128_preserve_flags'' o v s s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.lemma_is_machine_heap_update64 | val lemma_is_machine_heap_update64 (ptr: int) (v: nat64) (mh: machine_heap)
: Lemma (requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] | val lemma_is_machine_heap_update64 (ptr: int) (v: nat64) (mh: machine_heap)
: Lemma (requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] | let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
() | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 174,
"start_col": 0,
"start_line": 167
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> mh: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.Arch.MachineHeap_s.valid_addr64 ptr mh)
(ensures
Vale.Arch.MachineHeap_s.is_machine_heap_update mh
(Vale.Arch.MachineHeap_s.update_heap64 ptr v mh))
[
SMTPat (Vale.Arch.MachineHeap_s.is_machine_heap_update mh
(Vale.Arch.MachineHeap_s.update_heap64 ptr v mh))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat64",
"Vale.Arch.MachineHeap_s.machine_heap",
"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",
"Vale.Arch.MachineHeap_s.is_machine_heap_update",
"Vale.Arch.MachineHeap_s.update_heap64",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_is_machine_heap_update64 (ptr: int) (v: nat64) (mh: machine_heap)
: Lemma (requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] =
| reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
() | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.cf | val cf (flags: flags_t) : flag_val_t | val cf (flags: flags_t) : flag_val_t | let cf (flags:flags_t) : flag_val_t =
flags fCarry | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 357,
"start_col": 0,
"start_line": 356
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | flags: Vale.X64.Machine_Semantics_s.flags_t -> Vale.X64.Machine_Semantics_s.flag_val_t | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.flags_t",
"Vale.X64.Machine_s.fCarry",
"Vale.X64.Machine_Semantics_s.flag_val_t"
] | [] | false | false | false | true | false | let cf (flags: flags_t) : flag_val_t =
| flags fCarry | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_mem_and_taint | val update_mem_and_taint (ptr: int) (v: nat64) (s: machine_state) (t: taint) : machine_state | val update_mem_and_taint (ptr: int) (v: nat64) (s: machine_state) (t: taint) : machine_state | let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 183,
"start_col": 0,
"start_line": 176
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
ptr: Prims.int ->
v: Vale.Def.Types_s.nat64 ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"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.__proj__Mkmachine_state__item__ms_flags",
"Vale.Arch.Heap.heap_upd",
"Vale.Arch.MachineHeap_s.update_heap64",
"Vale.X64.Machine_Semantics_s.update_n",
"Vale.Arch.Heap.heap_taint",
"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",
"Prims.bool"
] | [] | false | false | false | true | false | let update_mem_and_taint (ptr: int) (v: nat64) (s: machine_state) (t: taint) : machine_state =
| if valid_addr64 ptr (heap_get s.ms_heap)
then
{
s with
ms_heap
=
heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_maddr | val eval_maddr (m: maddr) (s: machine_state) : int | val eval_maddr (m: maddr) (s: machine_state) : int | let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 101,
"end_line": 99,
"start_col": 0,
"start_line": 95
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | m: Vale.X64.Machine_s.maddr -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.maddr",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.int",
"Vale.X64.Machine_s.reg",
"Prims.op_Addition",
"Vale.X64.Machine_Semantics_s.eval_reg_int",
"FStar.Mul.op_Star"
] | [] | false | false | false | true | false | let eval_maddr (m: maddr) (s: machine_state) : int =
| match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_operand64' | val update_operand64' (o: operand64) (ins: ins) (v: nat64) (s: machine_state) : machine_state | val update_operand64' (o: operand64) (ins: ins) (v: nat64) (s: machine_state) : machine_state | let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags } | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 346,
"start_col": 0,
"start_line": 345
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
o: Vale.X64.Machine_s.operand64 ->
ins: Vale.X64.Machine_Semantics_s.ins ->
v: Vale.Def.Types_s.nat64 ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.machine_state",
"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",
"Vale.X64.Machine_Semantics_s.update_operand64_preserve_flags'"
] | [] | false | false | false | true | false | let update_operand64' (o: operand64) (ins: ins) (v: nat64) (s: machine_state) : machine_state =
| { (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags } | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_operand | val eval_operand (o: operand64) (s: machine_state) : nat64 | val eval_operand (o: operand64) (s: machine_state) : nat64 | let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 106,
"start_col": 0,
"start_line": 101
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_s.operand64 -> s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.Def.Types_s.nat64 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_Semantics_s.eval_reg_64",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_Semantics_s.eval_mem",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.X64.Machine_Semantics_s.eval_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.Def.Types_s.nat64"
] | [] | false | false | false | true | false | let eval_operand (o: operand64) (s: machine_state) : nat64 =
| match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.overflow | val overflow (flags: flags_t) : flag_val_t | val overflow (flags: flags_t) : flag_val_t | let overflow(flags:flags_t) : flag_val_t =
flags fOverflow | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 360,
"start_col": 0,
"start_line": 359
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | flags: Vale.X64.Machine_Semantics_s.flags_t -> Vale.X64.Machine_Semantics_s.flag_val_t | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.flags_t",
"Vale.X64.Machine_s.fOverflow",
"Vale.X64.Machine_Semantics_s.flag_val_t"
] | [] | false | false | false | true | false | let overflow (flags: flags_t) : flag_val_t =
| flags fOverflow | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.get_fst_ocmp | val get_fst_ocmp : o: Vale.X64.Machine_Semantics_s.ocmp
-> o1:
Vale.X64.Machine_s.operand64
{ Prims.op_Negation (OMem? o1 || OStack? o1) \/ Prims.op_Negation (OMem? o1 || OStack? o1) \/
Prims.op_Negation (OMem? o1 || OStack? o1) \/ Prims.op_Negation (OMem? o1 || OStack? o1) \/
Prims.op_Negation (OMem? o1 || OStack? o1) \/ Prims.op_Negation (OMem? o1 || OStack? o1) } | let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1 | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 73,
"start_col": 0,
"start_line": 72
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_Semantics_s.ocmp
-> o1:
Vale.X64.Machine_s.operand64
{ Prims.op_Negation (OMem? o1 || OStack? o1) \/ Prims.op_Negation (OMem? o1 || OStack? o1) \/
Prims.op_Negation (OMem? o1 || OStack? o1) \/ Prims.op_Negation (OMem? o1 || OStack? o1) \/
Prims.op_Negation (OMem? o1 || OStack? o1) \/ Prims.op_Negation (OMem? o1 || OStack? o1) } | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"Prims.l_or"
] | [] | false | false | false | false | false | let get_fst_ocmp (o: ocmp) =
| match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1 | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.eval_ocmp | val eval_ocmp (s: machine_state) (c: ocmp) : bool | val eval_ocmp (s: machine_state) (c: ocmp) : bool | let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 122,
"start_col": 0,
"start_line": 115
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | s: Vale.X64.Machine_Semantics_s.machine_state -> c: Vale.X64.Machine_Semantics_s.ocmp -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"Prims.op_Equality",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.eval_operand",
"Prims.op_disEquality",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.op_GreaterThan",
"Prims.bool"
] | [] | false | false | false | true | false | let eval_ocmp (s: machine_state) (c: ocmp) : bool =
| match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.match_n | val match_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint)
: Tot
(b:
bool
{ b <==>
(forall i. {:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[ i ] == t) }) (decreases n) | val match_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint)
: Tot
(b:
bool
{ b <==>
(forall i. {:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[ i ] == t) }) (decreases n) | let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 154,
"start_col": 0,
"start_line": 146
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
addr: Prims.int ->
n: Prims.nat ->
memTaint: Vale.Arch.HeapTypes_s.memTaint_t ->
t: Vale.Arch.HeapTypes_s.taint
-> Prims.Tot
(b:
Prims.bool
{ b <==>
(forall (i: Prims.int). {:pattern FStar.Map.sel memTaint i}
i >= addr /\ i < addr + n ==> memTaint.[ i ] == t) }) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.int",
"Prims.nat",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Arch.HeapTypes_s.taint",
"Prims.op_Equality",
"Prims.bool",
"Prims.op_disEquality",
"Vale.X64.Machine_Semantics_s.op_String_Access",
"Vale.X64.Machine_Semantics_s.match_n",
"Prims.op_Addition",
"Prims.op_Subtraction",
"Prims.l_iff",
"Prims.b2t",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Map.sel"
] | [
"recursion"
] | false | false | false | false | false | let rec match_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint)
: Tot
(b:
bool
{ b <==>
(forall i. {:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[ i ] == t) }) (decreases n) =
| if n = 0
then true
else if memTaint.[ addr ] <> t then false else match_n (addr + 1) (n - 1) memTaint t | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.free_stack' | val free_stack' (start finish: int) (st: machine_stack) : machine_stack | val free_stack' (start finish: int) (st: machine_stack) : machine_stack | let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 375,
"start_col": 0,
"start_line": 368
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | start: Prims.int -> finish: Prims.int -> st: Vale.X64.Machine_Semantics_s.machine_stack
-> Vale.X64.Machine_Semantics_s.machine_stack | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Vale.X64.Machine_Semantics_s.Machine_stack",
"Vale.Def.Words_s.nat8",
"FStar.Map.restrict",
"FStar.Set.set",
"Vale.Lib.Set.remove_between",
"FStar.Map.domain"
] | [] | false | false | false | true | false | let free_stack' (start finish: int) (st: machine_stack) : machine_stack =
| let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.lemma_is_machine_heap_update128 | val lemma_is_machine_heap_update128 (ptr: int) (v: quad32) (mh: machine_heap)
: Lemma (requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] | val lemma_is_machine_heap_update128 (ptr: int) (v: quad32) (mh: machine_heap)
: Lemma (requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] | let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 208,
"start_col": 0,
"start_line": 185
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> mh: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.Arch.MachineHeap_s.valid_addr128 ptr mh)
(ensures
Vale.Arch.MachineHeap_s.is_machine_heap_update mh
(Vale.Arch.MachineHeap_s.update_heap128 ptr v mh))
[
SMTPat (Vale.Arch.MachineHeap_s.is_machine_heap_update mh
(Vale.Arch.MachineHeap_s.update_heap128 ptr v mh))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.op_Addition",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Arch.MachineHeap_s.update_heap128_reveal",
"FStar.Pervasives.reveal_opaque",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.Arch.MachineHeap_s.update_heap32",
"Vale.Def.Words_s.nat32",
"Prims.l_and",
"Prims.b2t",
"Vale.Arch.MachineHeap_s.valid_addr",
"Prims.squash",
"Vale.Arch.MachineHeap_s.is_machine_heap_update",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Vale.Arch.MachineHeap_s.update_heap32_reveal",
"Vale.Arch.MachineHeap_s.update_heap128",
"Prims.Cons",
"FStar.Pervasives.smt_pat",
"Prims.logical"
] | [] | false | false | true | false | false | let lemma_is_machine_heap_update128 (ptr: int) (v: quad32) (mh: machine_heap)
: Lemma (requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] =
| let lemma_is_machine_heap_update32 (ptr: int) (v: nat32) (mh: machine_heap)
: Lemma
(requires
valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) =
update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.st | val st : a: Type -> Type | let st (a:Type) = machine_state -> a & machine_state | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 378,
"start_col": 0,
"start_line": 378
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | a: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | true | let st (a: Type) =
| machine_state -> a & machine_state | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.return | val return (#a: Type) (x: a) : st a | val return (#a: Type) (x: a) : st a | let return (#a:Type) (x:a) : st a =
fun s -> (x, s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 382,
"start_col": 0,
"start_line": 381
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | x: a -> Vale.X64.Machine_Semantics_s.st a | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let return (#a: Type) (x: a) : st a =
| fun s -> (x, s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.set | val set (s: machine_state) : st unit | val set (s: machine_state) : st unit | let set (s:machine_state) : st unit =
fun _ -> ((), s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 397,
"start_col": 0,
"start_line": 396
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | s: Vale.X64.Machine_Semantics_s.machine_state -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let set (s: machine_state) : st unit =
| fun _ -> ((), s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_src_operand | val valid_src_operand (o: operand64) (s: machine_state) : bool | val valid_src_operand (o: operand64) (s: machine_state) : bool | let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 260,
"start_col": 0,
"start_line": 255
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_s.operand64 -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.valid_src_stack64",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_src_operand (o: operand64) (s: machine_state) : bool =
| match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.fail | val fail:st unit | val fail:st unit | let fail : st unit =
fun s -> ((), {s with ms_ok = false}) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 401,
"start_col": 0,
"start_line": 400
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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.tuple2"
] | [] | false | false | false | true | false | let fail:st unit =
| fun s -> ((), { s with ms_ok = false }) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.check_imm | val check_imm (valid: bool) : st unit | val check_imm (valid: bool) : st unit | let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 408,
"start_col": 0,
"start_line": 404
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false}) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | valid: Prims.bool -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Machine_Semantics_s.return",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.fail",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let check_imm (valid: bool) : st unit =
| if valid then return () else fail | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.get | val get:st machine_state | val get:st machine_state | let get : st machine_state =
fun s -> (s, s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 393,
"start_col": 0,
"start_line": 392
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok}) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Vale.X64.Machine_Semantics_s.st Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let get:st machine_state =
| fun s -> (s, s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_src_operand64_and_taint | val valid_src_operand64_and_taint (o: operand64) (s: machine_state) : bool | val valid_src_operand64_and_taint (o: operand64) (s: machine_state) : bool | let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 271,
"start_col": 0,
"start_line": 262
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_s.operand64 -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Prims.op_AmpAmp",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.match_n",
"Vale.Arch.Heap.heap_taint",
"Prims.int",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.X64.Machine_Semantics_s.valid_src_stack64",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_src_operand64_and_taint (o: operand64) (s: machine_state) : bool =
| match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.check | val check (valid: (machine_state -> bool)) : st unit | val check (valid: (machine_state -> bool)) : st unit | let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 416,
"start_col": 0,
"start_line": 411
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | valid: (_: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool)
-> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.return",
"Vale.X64.Machine_Semantics_s.fail",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let check (valid: (machine_state -> bool)) : st unit =
| let* s = get in
if valid s then return () else fail | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_operand64_preserve_flags'' | val update_operand64_preserve_flags'' (o: operand64) (v: nat64) (s_orig s: machine_state)
: machine_state | val update_operand64_preserve_flags'' (o: operand64) (v: nat64) (s_orig s: machine_state)
: machine_state | let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 326,
"start_col": 0,
"start_line": 321
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
o: Vale.X64.Machine_s.operand64 ->
v: Vale.Def.Types_s.nat64 ->
s_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_Semantics_s.update_reg_64'",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_Semantics_s.update_mem_and_taint",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.X64.Machine_Semantics_s.update_stack_and_taint"
] | [] | false | false | false | true | false | let update_operand64_preserve_flags'' (o: operand64) (v: nat64) (s_orig s: machine_state)
: machine_state =
| match o with
| OConst _ -> { s with ms_ok = false }
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_ocmp | val valid_ocmp (c: ocmp) (s: machine_state) : bool | val valid_ocmp (c: ocmp) (s: machine_state) : bool | let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 291,
"start_col": 0,
"start_line": 284
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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.ocmp -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.ocmp",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.operand64",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_BarBar",
"Vale.X64.Machine_s.uu___is_OMem",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.uu___is_OStack",
"Prims.op_AmpAmp",
"Vale.X64.Machine_Semantics_s.valid_src_operand64_and_taint",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_ocmp (c: ocmp) (s: machine_state) : bool =
| match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.apply_option | val apply_option (#a: Type) (o: option a) (f: (a -> st unit)) : st unit | val apply_option (#a: Type) (o: option a) (f: (a -> st unit)) : st unit | let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 425,
"start_col": 0,
"start_line": 424
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: FStar.Pervasives.Native.option a -> f: (_: a -> Vale.X64.Machine_Semantics_s.st Prims.unit)
-> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.try_option"
] | [] | false | false | false | true | false | let apply_option (#a: Type) (o: option a) (f: (a -> st unit)) : st unit =
| try_option o f | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.run | val run (f: st unit) (s: machine_state) : machine_state | val run (f: st unit) (s: machine_state) : machine_state | let run (f:st unit) (s:machine_state) : machine_state = snd (f s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 428,
"start_col": 0,
"start_line": 428
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | f: Vale.X64.Machine_Semantics_s.st Prims.unit -> s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | true | false | let run (f: st unit) (s: machine_state) : machine_state =
| snd (f s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_src_operand128_and_taint | val valid_src_operand128_and_taint (o: operand128) (s: machine_state) : bool | val valid_src_operand128_and_taint (o: operand128) (s: machine_state) : bool | let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 282,
"start_col": 0,
"start_line": 273
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_s.operand128 -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Prims.op_AmpAmp",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.match_n",
"Vale.Arch.Heap.heap_taint",
"Prims.int",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.X64.Machine_Semantics_s.valid_src_stack128",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_src_operand128_and_taint (o: operand128) (s: machine_state) : bool =
| match o with
| OConst _ -> false
| OReg i -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_operand128_preserve_flags'' | val update_operand128_preserve_flags'' (o: operand128) (v: quad32) (s_orig s: machine_state)
: machine_state | val update_operand128_preserve_flags'' (o: operand128) (v: quad32) (s_orig s: machine_state)
: machine_state | let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 336,
"start_col": 0,
"start_line": 331
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
o: Vale.X64.Machine_s.operand128 ->
v: Vale.Def.Types_s.quad32 ->
s_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand128",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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",
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Machine_Semantics_s.update_reg_xmm'",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_Semantics_s.update_mem128_and_taint",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.X64.Machine_Semantics_s.update_stack128_and_taint"
] | [] | false | false | false | true | false | let update_operand128_preserve_flags'' (o: operand128) (v: quad32) (s_orig s: machine_state)
: machine_state =
| match o with
| OConst _ -> { s with ms_ok = false }
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_operand64_preserve_flags | val update_operand64_preserve_flags (dst: operand64) (v: nat64) : st unit | val update_operand64_preserve_flags (dst: operand64) (v: nat64) : st unit | let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 435,
"start_col": 0,
"start_line": 432
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | dst: Vale.X64.Machine_s.operand64 -> v: Vale.Def.Types_s.nat64
-> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.check",
"Vale.X64.Machine_Semantics_s.valid_dst_operand64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"Vale.X64.Machine_Semantics_s.update_operand64_preserve_flags'",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_operand64_preserve_flags (dst: operand64) (v: nat64) : st unit =
| let* _ = check (valid_dst_operand64 dst) in
let* s = get in
set (update_operand64_preserve_flags' dst v s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_rsp | val update_rsp (i: int) : st unit | val update_rsp (i: int) : st unit | let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 443,
"start_col": 0,
"start_line": 438
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Prims.int -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.check",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Subtraction",
"Vale.X64.Machine_Semantics_s.__proj__Machine_stack__item__initial_rsp",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Prims.bool",
"Prims.op_LessThanOrEqual",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"Vale.X64.Machine_Semantics_s.update_rsp'",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_rsp (i: int) : st unit =
| let* _ = check (fun s -> i >= s.ms_stack.initial_rsp - 4096) in
let* _ = check (fun s -> i <= s.ms_stack.initial_rsp) in
let* s = get in
set (update_rsp' i s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_xmm_preserve_flags | val update_xmm_preserve_flags (x: reg_xmm) (v: quad32) : st unit | val update_xmm_preserve_flags (x: reg_xmm) (v: quad32) : st unit | let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s ) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 455,
"start_col": 0,
"start_line": 453
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } ) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | x: Vale.X64.Machine_s.reg_xmm -> v: Vale.Def.Types_s.quad32
-> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg_xmm",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"Vale.X64.Machine_Semantics_s.update_reg_xmm'",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_xmm_preserve_flags (x: reg_xmm) (v: quad32) : st unit =
| let* s = get in
set (update_reg_xmm' x v s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_dst_operand64 | val valid_dst_operand64 (o: operand64) (s: machine_state) : bool | val valid_dst_operand64 (o: operand64) (s: machine_state) : bool | let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 312,
"start_col": 0,
"start_line": 307
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_s.operand64 -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Prims.op_Negation",
"Prims.op_Equality",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.valid_dst_stack64",
"Vale.X64.Machine_Semantics_s.eval_reg_64",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_dst_operand64 (o: operand64) (s: machine_state) : bool =
| match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_reg_xmm | val update_reg_xmm (x: reg_xmm) (ins: ins) (v: quad32) : st unit | val update_reg_xmm (x: reg_xmm) (ins: ins) (v: quad32) : st unit | let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } ) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 451,
"start_col": 0,
"start_line": 449
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | x: Vale.X64.Machine_s.reg_xmm -> ins: Vale.X64.Machine_Semantics_s.ins -> v: Vale.Def.Types_s.quad32
-> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.Def.Types_s.quad32",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"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",
"Vale.X64.Machine_Semantics_s.update_reg_xmm'",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_reg_xmm (x: reg_xmm) (ins: ins) (v: quad32) : st unit =
| let* s = get in
set ({ (update_reg_xmm' x v s) with ms_flags = havoc_flags }) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.valid_dst_operand128 | val valid_dst_operand128 (o: operand128) (s: machine_state) : bool | val valid_dst_operand128 (o: operand128) (s: machine_state) : bool | let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 319,
"start_col": 0,
"start_line": 314
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | o: Vale.X64.Machine_s.operand128 -> s: Vale.X64.Machine_Semantics_s.machine_state -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.X64.Machine_Semantics_s.eval_maddr",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.valid_dst_stack128",
"Vale.X64.Machine_Semantics_s.eval_reg_64",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Prims.bool"
] | [] | false | false | false | true | false | let valid_dst_operand128 (o: operand128) (s: machine_state) : bool =
| match o with
| OConst _ -> false
| OReg i -> true
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack | false |
Pulse.Elaborate.fst | Pulse.Elaborate.elab_open_commute' | val elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n)) | val elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n)) | let rec elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
// | Tm_PureApp e1 _ e2 ->
// elab_open_commute' e1 v n;
// elab_open_commute' e2 v n
| Tm_Inv p ->
elab_open_commute' p v n
| Tm_Pure p ->
elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> () | {
"file_name": "lib/steel/pulse/Pulse.Elaborate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 69,
"start_col": 0,
"start_line": 41
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Elaborate
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Elaborate.Core
// let rec elab_term_bv_sort (t:term)
// : Lemma
// (ensures
// (R.Tv_Var? (R.inspect_ln (elab_term t)) \/
// R.Tv_BVar? (R.inspect_ln (elab_term t))) ==>
// (match R.inspect_ln (elab_term t) with
// | R.Tv_Var bv
// | R.Tv_BVar bv ->
// let vv = R.inspect_bv bv in
// vv.bv_sort == RT.tun))
// = admit() | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Elaborate.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Naming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"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": 10,
"initial_ifuel": 10,
"max_fuel": 10,
"max_ifuel": 10,
"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.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 30,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.term -> n: Pulse.Syntax.Base.index
-> FStar.Pervasives.Lemma
(ensures
FStar.Reflection.Typing.subst_term (Pulse.Elaborate.Pure.elab_term e)
[FStar.Reflection.Typing.DT n (Pulse.Elaborate.Pure.elab_term v)] ==
Pulse.Elaborate.Pure.elab_term (Pulse.Syntax.Naming.open_term' e v n)) (decreases e) | FStar.Pervasives.Lemma | [
"",
"lemma"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Elaborate.elab_open_commute'",
"Prims.unit",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Prims.op_Addition",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.host_term",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.Typing.subst_term",
"Pulse.Elaborate.Pure.elab_term",
"Prims.Cons",
"FStar.Reflection.Typing.subst_elt",
"FStar.Reflection.Typing.DT",
"Prims.Nil",
"Pulse.Syntax.Naming.open_term'",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec elab_open_commute' (e v: term) (n: index)
: Lemma
(ensures RT.subst_term (elab_term e) [RT.DT n (elab_term v)] == elab_term (open_term' e v n))
(decreases e) =
| match e.t with
| Tm_Emp | Tm_Inames | Tm_EmpInames | Tm_VProp | Tm_Unknown -> ()
| Tm_Inv p -> elab_open_commute' p v n
| Tm_Pure p -> elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> () | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_cf | val update_cf (new_cf: bool) : st unit | val update_cf (new_cf: bool) : st unit | let update_cf (new_cf:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' s.ms_flags new_cf } ) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 463,
"start_col": 0,
"start_line": 461
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } )
let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s )
let update_flags (new_flags:flags_t) : st unit =
let* s = get in
set ( { s with ms_flags = new_flags } ) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | new_cf: Prims.bool -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"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.update_cf'",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_cf (new_cf: bool) : st unit =
| let* s = get in
set ({ s with ms_flags = update_cf' s.ms_flags new_cf }) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_flags | val update_flags (new_flags: flags_t) : st unit | val update_flags (new_flags: flags_t) : st unit | let update_flags (new_flags:flags_t) : st unit =
let* s = get in
set ( { s with ms_flags = new_flags } ) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 459,
"start_col": 0,
"start_line": 457
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } )
let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s ) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | new_flags: Vale.X64.Machine_Semantics_s.flags_t -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.flags_t",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"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.__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",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_flags (new_flags: flags_t) : st unit =
| let* s = get in
set ({ s with ms_flags = new_flags }) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_of | val update_of (new_of: bool) : st unit | val update_of (new_of: bool) : st unit | let update_of (new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_of' s.ms_flags new_of } ) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 467,
"start_col": 0,
"start_line": 465
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } )
let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s )
let update_flags (new_flags:flags_t) : st unit =
let* s = get in
set ( { s with ms_flags = new_flags } )
let update_cf (new_cf:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' s.ms_flags new_cf } ) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | new_of: Prims.bool -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"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.update_of'",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_of (new_of: bool) : st unit =
| let* s = get in
set ({ s with ms_flags = update_of' s.ms_flags new_of }) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_reg_64 | val update_reg_64 (r: reg_64) (v: nat64) : st unit | val update_reg_64 (r: reg_64) (v: nat64) : st unit | let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 447,
"start_col": 0,
"start_line": 445
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | r: Vale.X64.Machine_s.reg_64 -> v: Vale.Def.Types_s.nat64
-> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.reg_64",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"Vale.X64.Machine_Semantics_s.update_reg_64'",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_reg_64 (r: reg_64) (v: nat64) : st unit =
| let* s = get in
set (update_reg_64' r v s) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_cf_of | val update_cf_of (new_cf new_of: bool) : st unit | val update_cf_of (new_cf new_of: bool) : st unit | let update_cf_of (new_cf new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' (update_of' s.ms_flags new_of) new_cf } ) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 471,
"start_col": 0,
"start_line": 469
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } )
let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s )
let update_flags (new_flags:flags_t) : st unit =
let* s = get in
set ( { s with ms_flags = new_flags } )
let update_cf (new_cf:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' s.ms_flags new_cf } )
let update_of (new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_of' s.ms_flags new_of } ) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | new_cf: Prims.bool -> new_of: Prims.bool -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"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.update_cf'",
"Vale.X64.Machine_Semantics_s.update_of'",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let update_cf_of (new_cf new_of: bool) : st unit =
| let* s = get in
set ({ s with ms_flags = update_cf' (update_of' s.ms_flags new_of) new_cf }) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.free_stack | val free_stack (start finish: int) : st unit | val free_stack (start finish: int) : st unit | let free_stack (start finish:int) : st unit =
let* s = get in
set ( { s with ms_stack = free_stack' start finish s.ms_stack} ) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 475,
"start_col": 0,
"start_line": 473
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } )
let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s )
let update_flags (new_flags:flags_t) : st unit =
let* s = get in
set ( { s with ms_flags = new_flags } )
let update_cf (new_cf:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' s.ms_flags new_cf } )
let update_of (new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_of' s.ms_flags new_of } )
let update_cf_of (new_cf new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' (update_of' s.ms_flags new_of) new_cf } ) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | start: Prims.int -> finish: Prims.int -> Vale.X64.Machine_Semantics_s.st Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.get",
"Vale.X64.Machine_Semantics_s.set",
"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.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.free_stack'",
"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",
"Vale.X64.Machine_Semantics_s.st"
] | [] | false | false | false | true | false | let free_stack (start finish: int) : st unit =
| let* s = get in
set ({ s with ms_stack = free_stack' start finish s.ms_stack }) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_rsp' | val update_rsp' (new_rsp: int) (s: machine_state) : machine_state | val update_rsp' (new_rsp: int) (s: machine_state) : machine_state | let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 354,
"start_col": 0,
"start_line": 348
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags } | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | new_rsp: Prims.int -> s: Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Vale.Def.Types_s.nat8",
"Prims.op_AmpAmp",
"Prims.op_Subtraction",
"Prims.op_LessThanOrEqual",
"Vale.X64.Machine_Semantics_s.update_reg_64'",
"Vale.X64.Machine_s.rRsp",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack"
] | [] | false | false | false | true | false | let update_rsp' (new_rsp: int) (s: machine_state) : machine_state =
| let Machine_stack init_rsp mem = s.ms_stack in
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then update_reg_64' rRsp new_rsp s else s | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_cf' | val update_cf' (flags: flags_t) (new_cf: bool) : (new_flags: flags_t{cf new_flags == Some new_cf}) | val update_cf' (flags: flags_t) (new_cf: bool) : (new_flags: flags_t{cf new_flags == Some new_cf}) | let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 99,
"end_line": 363,
"start_col": 0,
"start_line": 362
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | flags: Vale.X64.Machine_Semantics_s.flags_t -> new_cf: Prims.bool
-> new_flags:
Vale.X64.Machine_Semantics_s.flags_t
{Vale.X64.Machine_Semantics_s.cf new_flags == FStar.Pervasives.Native.Some new_cf} | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.flags_t",
"Prims.bool",
"FStar.FunctionalExtensionality.on_dom",
"Vale.X64.Machine_s.flag",
"FStar.Pervasives.Native.option",
"Prims.op_Equality",
"Vale.X64.Machine_s.fCarry",
"FStar.Pervasives.Native.Some",
"Prims.eq2",
"Vale.X64.Machine_Semantics_s.cf"
] | [] | false | false | false | false | false | let update_cf' (flags: flags_t) (new_cf: bool) : (new_flags: flags_t{cf new_flags == Some new_cf}) =
| FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f) | false |
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.instr_apply_eval | val instr_apply_eval
(outs: list instr_out)
(args: list instr_operand)
(f: instr_eval_t outs args)
(oprs: instr_operands_t outs args)
(s: machine_state)
: option (instr_ret_t outs) | val instr_apply_eval
(outs: list instr_out)
(args: list instr_operand)
(f: instr_eval_t outs args)
(oprs: instr_operands_t outs args)
(s: machine_state)
: option (instr_ret_t outs) | let instr_apply_eval
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args) (s:machine_state)
: option (instr_ret_t outs) =
instr_apply_eval_inouts outs outs args f oprs s | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 615,
"start_col": 0,
"start_line": 611
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } )
let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s )
let update_flags (new_flags:flags_t) : st unit =
let* s = get in
set ( { s with ms_flags = new_flags } )
let update_cf (new_cf:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' s.ms_flags new_cf } )
let update_of (new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_of' s.ms_flags new_of } )
let update_cf_of (new_cf new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' (update_of' s.ms_flags new_of) new_cf } )
let free_stack (start finish:int) : st unit =
let* s = get in
set ( { s with ms_stack = free_stack' start finish s.ms_stack} )
let bind_option (#a #b:Type) (v:option a) (f:a -> option b) : option b =
match v with
| None -> None
| Some x -> f x
let operand_obs (s:machine_state) (o:operand64) : list observation =
match o with
| OConst _ | OReg _ -> []
| OMem (m, _) | OStack (m, _) -> [MemAccess (eval_maddr m s)]
[@instr_attr]
let operand_obs128 (s:machine_state) (op:operand128) : list observation =
match op with
| OConst _ | OReg _ -> []
| OMem (m, _) | OStack (m, _) -> [MemAccess (eval_maddr m s)]
[@instr_attr]
let obs_operand_explicit
(i:instr_operand_explicit)
(o:instr_operand_t i)
(s:machine_state) : list observation =
match i with
| IOp64 -> operand_obs s o
| IOpXmm -> operand_obs128 s o
[@instr_attr]
let obs_operand_implicit
(i:instr_operand_implicit)
(s:machine_state) : list observation =
match i with
| IOp64One o -> operand_obs s o
| IOpXmmOne o -> operand_obs128 s o
| IOpFlagsCf | IOpFlagsOf -> []
[@instr_attr]
let rec obs_args
(args:list instr_operand)
(oprs:instr_operands_t_args args)
(s:machine_state) : list observation =
match args with
| [] -> []
| i::args ->
match i with
| IOpEx i ->
let oprs = coerce oprs in
obs_operand_explicit i (fst oprs) s @ obs_args args (snd oprs) s
| IOpIm i ->
obs_operand_implicit i s @ obs_args args (coerce oprs) s
[@instr_attr]
let rec obs_inouts
(inouts:list instr_out)
(args:list instr_operand)
(oprs:instr_operands_t inouts args)
(s:machine_state) : list observation =
match inouts with
| [] -> obs_args args oprs s
| (_, i)::inouts ->
let (v, oprs) =
match i with
| IOpEx i ->
let oprs = coerce oprs in
(obs_operand_explicit i (fst oprs) s), snd oprs
| IOpIm i -> obs_operand_implicit i s, coerce oprs
in v @ obs_inouts inouts args oprs s
[@instr_attr]
let ins_obs (ins:ins) (s:machine_state) : list observation =
match ins with
| BC.Instr (InstrTypeRecord #outs #args _) oprs _ -> obs_inouts outs args oprs s
| BC.Push src _ -> operand_obs s src
| BC.Pop dst _ -> operand_obs s dst
| BC.Alloc _ | BC.Dealloc _ -> []
[@instr_attr]
let instr_eval_operand_explicit (i:instr_operand_explicit) (o:instr_operand_t i) (s:machine_state) : option (instr_val_t (IOpEx i)) =
match i with
| IOp64 -> if valid_src_operand64_and_taint o s then Some (eval_operand o s) else None
| IOpXmm -> if valid_src_operand128_and_taint o s then Some (eval_mov128_op o s) else None
[@instr_attr]
let instr_eval_operand_implicit (i:instr_operand_implicit) (s:machine_state) : option (instr_val_t (IOpIm i)) =
match i with
| IOp64One o -> if valid_src_operand64_and_taint o s then Some (eval_operand o s) else None
| IOpXmmOne o -> if valid_src_operand128_and_taint o s then Some (eval_mov128_op o s) else None
| IOpFlagsCf -> cf s.ms_flags
| IOpFlagsOf -> overflow s.ms_flags
[@instr_attr]
let rec instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s:machine_state)
: option (instr_ret_t outs) =
match args with
| [] -> f
| i::args ->
let (v, oprs) =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
bind_option v (fun v -> instr_apply_eval_args outs args (f v) oprs s)
[@instr_attr]
let rec instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s:machine_state)
: option (instr_ret_t outs) =
match inouts with
| [] -> instr_apply_eval_args outs args f oprs s
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
instr_apply_eval_inouts outs inouts args (coerce f) oprs s
| (InOut, i)::inouts ->
let (v, oprs) =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
bind_option v (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s)
(*
Take the all the input operands for an instruction and:
- check that they are valid
- evaluate them
- apply the instruction's evaluator function f to the evaluated operands
*) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 ->
f: Vale.X64.Instruction_s.instr_eval_t outs args ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Native.option (Vale.X64.Instruction_s.instr_ret_t outs) | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_eval_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_ret_t"
] | [] | false | false | false | false | false | let instr_apply_eval
(outs: list instr_out)
(args: list instr_operand)
(f: instr_eval_t outs args)
(oprs: instr_operands_t outs args)
(s: machine_state)
: option (instr_ret_t outs) =
| instr_apply_eval_inouts outs outs args f oprs s | false |
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_3p | val uint8_3p : Type0 | let uint8_3p = uint8_1p & uint8_2p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 10,
"start_col": 0,
"start_line": 10
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_1p",
"Hacl.Impl.SHA2.Types.uint8_2p"
] | [] | false | false | false | true | true | let uint8_3p =
| uint8_1p & uint8_2p | false |
|
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_1p | val uint8_1p : Type0 | let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 4,
"start_col": 0,
"start_line": 4
} | module Hacl.Impl.SHA2.Types | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"FStar.UInt8.t"
] | [] | false | false | false | true | true | let uint8_1p =
| LowStar.Buffer.buffer FStar.UInt8.t | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.state_or_fail | val state_or_fail (s: machine_state) (b: bool) (s': machine_state) : machine_state | val state_or_fail (s: machine_state) (b: bool) (s': machine_state) : machine_state | let state_or_fail (s:machine_state) (b:bool) (s':machine_state) : machine_state =
if b then s' else {s with ms_ok = false} | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 618,
"start_col": 0,
"start_line": 617
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f)
let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f)
let free_stack' (start finish:int) (st:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = st in
let domain = Map.domain mem in
// Returns the domain, without elements between start and finish
let restricted_domain = Vale.Lib.Set.remove_between domain start finish in
// The new domain of the stack does not contain elements between start and finish
let new_mem = Map.restrict restricted_domain mem in
Machine_stack init_rsp new_mem
// Define a stateful monad to simplify defining the instruction semantics
let st (a:Type) = machine_state -> a & machine_state
unfold
let return (#a:Type) (x:a) : st a =
fun s -> (x, s)
unfold
let (let*) (#a:Type) (#b:Type) (m:st a) (f:a -> st b) : st b =
fun s0 ->
let (x, s1) = m s0 in
let (y, s2) = f x s1 in
(y, {s2 with ms_ok = s0.ms_ok && s1.ms_ok && s2.ms_ok})
unfold
let get : st machine_state =
fun s -> (s, s)
unfold
let set (s:machine_state) : st unit =
fun _ -> ((), s)
unfold
let fail : st unit =
fun s -> ((), {s with ms_ok = false})
unfold
let check_imm (valid:bool) : st unit =
if valid then
return ()
else
fail
unfold
let check (valid: machine_state -> bool) : st unit =
let* s = get in
if valid s then
return ()
else
fail
unfold
let try_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
match o with
| None -> fail
| Some x -> f x
let apply_option (#a:Type) (o:option a) (f:a -> st unit) : st unit =
try_option o f
unfold
let run (f:st unit) (s:machine_state) : machine_state = snd (f s)
// Monadic update operations
unfold
let update_operand64_preserve_flags (dst:operand64) (v:nat64) : st unit =
check (valid_dst_operand64 dst);*
let* s = get in
set (update_operand64_preserve_flags' dst v s)
unfold
let update_rsp (i:int) : st unit =
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
check (fun s -> i >= s.ms_stack.initial_rsp - 4096);*
check (fun s -> i <= s.ms_stack.initial_rsp);*
let* s = get in
set (update_rsp' i s)
let update_reg_64 (r:reg_64) (v:nat64) : st unit =
let* s = get in
set (update_reg_64' r v s)
let update_reg_xmm (x:reg_xmm) (ins:ins) (v:quad32) : st unit =
let* s = get in
set ( { (update_reg_xmm' x v s) with ms_flags = havoc_flags } )
let update_xmm_preserve_flags (x:reg_xmm) (v:quad32) : st unit =
let* s = get in
set ( update_reg_xmm' x v s )
let update_flags (new_flags:flags_t) : st unit =
let* s = get in
set ( { s with ms_flags = new_flags } )
let update_cf (new_cf:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' s.ms_flags new_cf } )
let update_of (new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_of' s.ms_flags new_of } )
let update_cf_of (new_cf new_of:bool) : st unit =
let* s = get in
set ( { s with ms_flags = update_cf' (update_of' s.ms_flags new_of) new_cf } )
let free_stack (start finish:int) : st unit =
let* s = get in
set ( { s with ms_stack = free_stack' start finish s.ms_stack} )
let bind_option (#a #b:Type) (v:option a) (f:a -> option b) : option b =
match v with
| None -> None
| Some x -> f x
let operand_obs (s:machine_state) (o:operand64) : list observation =
match o with
| OConst _ | OReg _ -> []
| OMem (m, _) | OStack (m, _) -> [MemAccess (eval_maddr m s)]
[@instr_attr]
let operand_obs128 (s:machine_state) (op:operand128) : list observation =
match op with
| OConst _ | OReg _ -> []
| OMem (m, _) | OStack (m, _) -> [MemAccess (eval_maddr m s)]
[@instr_attr]
let obs_operand_explicit
(i:instr_operand_explicit)
(o:instr_operand_t i)
(s:machine_state) : list observation =
match i with
| IOp64 -> operand_obs s o
| IOpXmm -> operand_obs128 s o
[@instr_attr]
let obs_operand_implicit
(i:instr_operand_implicit)
(s:machine_state) : list observation =
match i with
| IOp64One o -> operand_obs s o
| IOpXmmOne o -> operand_obs128 s o
| IOpFlagsCf | IOpFlagsOf -> []
[@instr_attr]
let rec obs_args
(args:list instr_operand)
(oprs:instr_operands_t_args args)
(s:machine_state) : list observation =
match args with
| [] -> []
| i::args ->
match i with
| IOpEx i ->
let oprs = coerce oprs in
obs_operand_explicit i (fst oprs) s @ obs_args args (snd oprs) s
| IOpIm i ->
obs_operand_implicit i s @ obs_args args (coerce oprs) s
[@instr_attr]
let rec obs_inouts
(inouts:list instr_out)
(args:list instr_operand)
(oprs:instr_operands_t inouts args)
(s:machine_state) : list observation =
match inouts with
| [] -> obs_args args oprs s
| (_, i)::inouts ->
let (v, oprs) =
match i with
| IOpEx i ->
let oprs = coerce oprs in
(obs_operand_explicit i (fst oprs) s), snd oprs
| IOpIm i -> obs_operand_implicit i s, coerce oprs
in v @ obs_inouts inouts args oprs s
[@instr_attr]
let ins_obs (ins:ins) (s:machine_state) : list observation =
match ins with
| BC.Instr (InstrTypeRecord #outs #args _) oprs _ -> obs_inouts outs args oprs s
| BC.Push src _ -> operand_obs s src
| BC.Pop dst _ -> operand_obs s dst
| BC.Alloc _ | BC.Dealloc _ -> []
[@instr_attr]
let instr_eval_operand_explicit (i:instr_operand_explicit) (o:instr_operand_t i) (s:machine_state) : option (instr_val_t (IOpEx i)) =
match i with
| IOp64 -> if valid_src_operand64_and_taint o s then Some (eval_operand o s) else None
| IOpXmm -> if valid_src_operand128_and_taint o s then Some (eval_mov128_op o s) else None
[@instr_attr]
let instr_eval_operand_implicit (i:instr_operand_implicit) (s:machine_state) : option (instr_val_t (IOpIm i)) =
match i with
| IOp64One o -> if valid_src_operand64_and_taint o s then Some (eval_operand o s) else None
| IOpXmmOne o -> if valid_src_operand128_and_taint o s then Some (eval_mov128_op o s) else None
| IOpFlagsCf -> cf s.ms_flags
| IOpFlagsOf -> overflow s.ms_flags
[@instr_attr]
let rec instr_apply_eval_args
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args) (s:machine_state)
: option (instr_ret_t outs) =
match args with
| [] -> f
| i::args ->
let (v, oprs) =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
bind_option v (fun v -> instr_apply_eval_args outs args (f v) oprs s)
[@instr_attr]
let rec instr_apply_eval_inouts
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args) (s:machine_state)
: option (instr_ret_t outs) =
match inouts with
| [] -> instr_apply_eval_args outs args f oprs s
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
instr_apply_eval_inouts outs inouts args (coerce f) oprs s
| (InOut, i)::inouts ->
let (v, oprs) =
match i with
| IOpEx i -> let oprs = coerce oprs in (instr_eval_operand_explicit i (fst oprs) s, snd oprs)
| IOpIm i -> (instr_eval_operand_implicit i s, coerce oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
bind_option v (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s)
(*
Take the all the input operands for an instruction and:
- check that they are valid
- evaluate them
- apply the instruction's evaluator function f to the evaluated operands
*)
[@instr_attr]
let instr_apply_eval
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args) (s:machine_state)
: option (instr_ret_t outs) =
instr_apply_eval_inouts outs outs args f oprs s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 |
s: Vale.X64.Machine_Semantics_s.machine_state ->
b: Prims.bool ->
s': Vale.X64.Machine_Semantics_s.machine_state
-> Vale.X64.Machine_Semantics_s.machine_state | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_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"
] | [] | false | false | false | true | false | let state_or_fail (s: machine_state) (b: bool) (s': machine_state) : machine_state =
| if b then s' else { s with ms_ok = false } | false |
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_4p | val uint8_4p : Type0 | let uint8_4p = uint8_1p & uint8_3p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 11,
"start_col": 0,
"start_line": 11
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *)
let uint8_2p = uint8_1p & uint8_1p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_1p",
"Hacl.Impl.SHA2.Types.uint8_3p"
] | [] | false | false | false | true | true | let uint8_4p =
| uint8_1p & uint8_3p | false |
|
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_2p | val uint8_2p : Type0 | let uint8_2p = uint8_1p & uint8_1p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 9,
"start_col": 0,
"start_line": 9
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_1p"
] | [] | false | false | false | true | true | let uint8_2p =
| uint8_1p & uint8_1p | false |
|
Vale.X64.Machine_Semantics_s.fst | Vale.X64.Machine_Semantics_s.update_of' | val update_of' (flags: flags_t) (new_of: bool)
: (new_flags: flags_t{overflow new_flags == Some new_of}) | val update_of' (flags: flags_t) (new_of: bool)
: (new_flags: flags_t{overflow new_flags == Some new_of}) | let update_of' (flags:flags_t) (new_of:bool) : (new_flags:flags_t{overflow new_flags == Some new_of}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f) | {
"file_name": "vale/specs/hardware/Vale.X64.Machine_Semantics_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 102,
"end_line": 366,
"start_col": 0,
"start_line": 365
} | module Vale.X64.Machine_Semantics_s
open FStar.Mul
open FStar.List.Tot
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
include Vale.Arch.MachineHeap_s
open Vale.Arch.HeapTypes_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.CPU_Features_s
open Vale.Def.Words_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open FStar.Seq.Base
module BC = Vale.X64.Bytes_Code_s
//type uint64:eqtype = UInt64.t
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
//TODO: [@"opaque_to_smt"]
let equals_instr (x1 x2:instr_t_record) : Type0 =
squash (x1 == x2)
noeq type instr_annotation (it:instr_t_record) =
| AnnotateNone : instr_annotation it
| AnnotateXor64 : equals_instr it (InstrTypeRecord ins_Xor64) -> instr_annotation it
| AnnotatePxor : equals_instr it (InstrTypeRecord ins_Pxor) -> instr_annotation it
| AnnotateVPxor : equals_instr it (InstrTypeRecord ins_VPxor) -> instr_annotation it
| AnnotateGhost : equals_instr it (InstrTypeRecord ins_Ghost) -> instr_annotation it
| AnnotateComment : s:string{it == (InstrTypeRecord (ins_Comment s))} -> instr_annotation it
| AnnotateLargeComment : s:string{it == (InstrTypeRecord (ins_LargeComment s))} -> instr_annotation it
| AnnotateNewline : equals_instr it (InstrTypeRecord ins_Newline) -> instr_annotation it
| AnnotateSpace : n:nat{it == (InstrTypeRecord (ins_Space n))} -> instr_annotation it
| AnnotateMovbe64 : equals_instr it (InstrTypeRecord ins_MovBe64) -> instr_annotation it
| AnnotateMov64 : equals_instr it (InstrTypeRecord ins_Mov64) -> instr_annotation it
| AnnotatePrefetchnta : equals_instr it (InstrTypeRecord ins_Prefetchnta) -> instr_annotation it
let ins = BC.instruction_t instr_annotation
let ocmp = BC.ocmp
let code = BC.code_t instr_annotation
let codes = BC.codes_t instr_annotation
noeq
type machine_stack =
| Machine_stack:
initial_rsp:nat64{initial_rsp >= 4096} -> // Initial rsp pointer when entering the function
stack_mem:Map.t int nat8 -> // Stack contents
machine_stack
unfold let flag_val_t = option bool // HACK: this shouldn't have to be unfolded (it has to do with the lambda in FStar.FunctionalExtensionality.(^->))
type flags_t = FStar.FunctionalExtensionality.restricted_t flag (fun _ -> flag_val_t)
type regs_t = FStar.FunctionalExtensionality.restricted_t reg t_reg
noeq
type machine_state = {
ms_ok: bool;
ms_regs: regs_t;
ms_flags: flags_t;
ms_heap: heap_impl;
ms_stack: machine_stack;
ms_stackTaint: memTaint_t;
ms_trace: list observation;
}
let get_fst_ocmp (o:ocmp) = match o with
| BC.OEq o1 _ | BC.ONe o1 _ | BC.OLe o1 _ | BC.OGe o1 _ | BC.OLt o1 _ | BC.OGt o1 _ -> o1
let get_snd_ocmp (o:ocmp) = match o with
| BC.OEq _ o2 | BC.ONe _ o2 | BC.OLe _ o2 | BC.OGe _ o2 | BC.OLt _ o2 | BC.OGt _ o2 -> o2
unfold let eval_reg (r:reg) (s:machine_state) : t_reg r = s.ms_regs r
unfold let eval_reg_64 (r:reg_64) (s:machine_state) : nat64 = eval_reg (Reg 0 r) s
unfold let eval_reg_xmm (r:reg_xmm) (s:machine_state) : quad32 = eval_reg (Reg 1 r) s
unfold let eval_reg_int (r:reg) (s:machine_state) : int = t_reg_to_int r.rf (eval_reg r s)
unfold let eval_mem (ptr:int) (s:machine_state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
unfold let eval_mem128 (ptr:int) (s:machine_state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 =
let Machine_stack _ mem = s in
get_heap_val64 ptr mem
unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 =
let Machine_stack _ mem = s in
get_heap_val128 ptr mem
[@va_qattr]
let eval_maddr (m:maddr) (s:machine_state) : int =
match m with
| MConst n -> n
| MReg r offset -> (eval_reg_int r s) + offset
| MIndex base scale index offset -> (eval_reg_int base s) + scale * (eval_reg_int index s) + offset
let eval_operand (o:operand64) (s:machine_state) : nat64 =
match o with
| OConst n -> n
| OReg r -> eval_reg_64 r s
| OMem (m, _) -> eval_mem (eval_maddr m s) s
| OStack (m, _) -> eval_stack (eval_maddr m s) s.ms_stack
let eval_mov128_op (o:operand128) (s:machine_state) : quad32 =
match o with
| OConst c -> c
| OReg i -> eval_reg_xmm i s
| OMem (m, _) -> eval_mem128 (eval_maddr m s) s
| OStack (m, _) -> eval_stack128 (eval_maddr m s) s.ms_stack
let eval_ocmp (s:machine_state) (c:ocmp) : bool =
match c with
| BC.OEq o1 o2 -> eval_operand o1 s = eval_operand o2 s
| BC.ONe o1 o2 -> eval_operand o1 s <> eval_operand o2 s
| BC.OLe o1 o2 -> eval_operand o1 s <= eval_operand o2 s
| BC.OGe o1 o2 -> eval_operand o1 s >= eval_operand o2 s
| BC.OLt o1 o2 -> eval_operand o1 s < eval_operand o2 s
| BC.OGt o1 o2 -> eval_operand o1 s > eval_operand o2 s
[@"opaque_to_smt"]
let eval_ocmp_opaque (s:machine_state) (c:ocmp) : bool = eval_ocmp s c
let update_reg' (r:reg) (v:t_reg r) (s:machine_state) : machine_state =
{s with ms_regs = FStar.FunctionalExtensionality.on_dom reg (fun r' -> if r' = r then v else s.ms_regs r')}
let update_reg_64' (r:reg_64) (v:nat64) (s:machine_state) : machine_state =
update_reg' (Reg 0 r) v s
let update_reg_xmm' (r:reg_xmm) (v:quad32) (s:machine_state) : machine_state =
update_reg' (Reg 1 r) v s
//val mod_8: (n:nat{n < pow2_64}) -> nat8
//let mod_8 n = n % 0x100
(*
Check if the taint annotation of a memory operand matches the taint in the memory map.
Evaluation will fail in case of a mismatch.
This allows the taint analysis to learn information about the memory map from the annotation,
assuming that the code has been verified not to fail.
(Note that this only relates to memory maps, so non-memory operands need no annotation.)
*)
[@"opaque_to_smt"]
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (b:bool{b <==>
(forall i.{:pattern (memTaint `Map.sel` i)}
(i >= addr /\ i < addr + n) ==> memTaint.[i] == t)})
(decreases n)
=
if n = 0 then true
else if memTaint.[addr] <> t then false
else match_n (addr + 1) (n - 1) memTaint t
[@"opaque_to_smt"]
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint)
: Tot (m:memTaint_t{(
forall i.{:pattern (m `Map.sel` i)}
((i >= addr /\ i < addr + n) ==> m.[i] == t) /\
((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))})
(decreases n)
=
if n = 0 then memTaint
else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma
(requires valid_addr64 ptr mh)
(ensures is_machine_heap_update mh (update_heap64 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))]
=
reveal_opaque (`%valid_addr64) valid_addr64;
update_heap64_reveal ();
()
let update_mem_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
if valid_addr64 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap64 ptr v (heap_get s.ms_heap))
(update_n ptr 8 (heap_taint s.ms_heap) t)
}
else s
let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma
(requires valid_addr128 ptr mh)
(ensures is_machine_heap_update mh (update_heap128 ptr v mh))
[SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))]
=
let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma
(requires
valid_addr ptr mh /\
valid_addr (ptr + 1) mh /\
valid_addr (ptr + 2) mh /\
valid_addr (ptr + 3) mh
)
(ensures is_machine_heap_update mh (update_heap32 ptr v mh))
= update_heap32_reveal ()
in
let mem1 = update_heap32 ptr v.lo0 mh in
let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in
let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in
reveal_opaque (`%valid_addr128) valid_addr128;
update_heap128_reveal ();
lemma_is_machine_heap_update32 ptr v.lo0 mh;
lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1;
lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2;
lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3
let update_mem128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
if valid_addr128 ptr (heap_get s.ms_heap) then
{ s with
ms_heap = heap_upd s.ms_heap
(update_heap128 ptr v (heap_get s.ms_heap))
(update_n ptr 16 (heap_taint s.ms_heap) t)
}
else s
unfold
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap64 ptr v mem in
Machine_stack init_rsp mem
unfold
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack =
let Machine_stack init_rsp mem = s in
let mem = update_heap128 ptr v mem in
Machine_stack init_rsp mem
let update_stack_and_taint (ptr:int) (v:nat64) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack64' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 8 s.ms_stackTaint t;
}
let update_stack128_and_taint (ptr:int) (v:quad32) (s:machine_state) (t:taint) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
{ s with
ms_stack = update_stack128' ptr v s.ms_stack;
ms_stackTaint = update_n ptr 16 s.ms_stackTaint t
}
unfold
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr64 ptr mem
unfold
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
valid_addr128 ptr mem
let valid_src_operand (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, t) -> valid_src_stack64 (eval_maddr m s) s.ms_stack
let valid_src_operand64_and_taint (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> true
| OReg r -> true
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr64 ptr (heap_get s.ms_heap) && match_n ptr 8 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
let valid_src_operand128_and_taint (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, t) ->
let ptr = eval_maddr m s in
valid_addr128 ptr (heap_get s.ms_heap) && match_n ptr 16 (heap_taint s.ms_heap) t
| OStack (m, t) ->
let ptr = eval_maddr m s in
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
let valid_ocmp (c:ocmp) (s:machine_state) : bool =
match c with
| BC.OEq o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.ONe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGe o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OLt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
| BC.OGt o1 o2 -> valid_src_operand64_and_taint o1 s && valid_src_operand64_and_taint o2 s
[@"opaque_to_smt"]
let valid_ocmp_opaque (c:ocmp) (s:machine_state) : bool = valid_ocmp c s
unfold
let valid_dst_stack64 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 8 <= init_rsp
unfold
let valid_dst_stack128 (rsp:nat64) (ptr:int) (st:machine_stack) : bool =
let Machine_stack init_rsp mem = st in
// We are allowed to store anywhere between rRsp and the initial stack pointer
ptr >= rsp && ptr + 16 <= init_rsp
let valid_dst_operand64 (o:operand64) (s:machine_state) : bool =
match o with
| OConst n -> false
| OReg r -> not (rRsp = r)
| OMem (m, _) -> valid_addr64 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack64 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let valid_dst_operand128 (o:operand128) (s:machine_state) : bool =
match o with
| OConst _ -> false
| OReg i -> true // We leave it to the printer/assembler to object to invalid XMM indices
| OMem (m, _) -> valid_addr128 (eval_maddr m s) (heap_get s.ms_heap)
| OStack (m, _) -> valid_dst_stack128 (eval_reg_64 rRsp s) (eval_maddr m s) s.ms_stack
let update_operand64_preserve_flags'' (o:operand64) (v:nat64) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg r -> update_reg_64' r v s
| OMem (m, t) -> update_mem_and_taint (eval_maddr m s_orig) v s t // see valid_buf_maddr64 for how eval_maddr connects to b and i
| OStack (m, t) -> update_stack_and_taint (eval_maddr m s_orig) v s t
let update_operand64_preserve_flags' (o:operand64) (v:nat64) (s:machine_state) : machine_state =
update_operand64_preserve_flags'' o v s s
let update_operand128_preserve_flags'' (o:operand128) (v:quad32) (s_orig s:machine_state) : machine_state =
match o with
| OConst _ -> {s with ms_ok = false}
| OReg i -> update_reg_xmm' i v s
| OMem (m, t) -> update_mem128_and_taint (eval_maddr m s_orig) v s t
| OStack (m, t) -> update_stack128_and_taint (eval_maddr m s_orig) v s t
let update_operand128_preserve_flags' (o:operand128) (v:quad32) (s:machine_state) : machine_state =
update_operand128_preserve_flags'' o v s s
let flags_none (f:flag) : flag_val_t = None
let havoc_flags : flags_t = FStar.FunctionalExtensionality.on_dom flag flags_none
// Default version havocs flags
let update_operand64' (o:operand64) (ins:ins) (v:nat64) (s:machine_state) : machine_state =
{ (update_operand64_preserve_flags' o v s) with ms_flags = havoc_flags }
let update_rsp' (new_rsp:int) (s:machine_state) : machine_state =
let Machine_stack init_rsp mem = s.ms_stack in
// Only modify the stack pointer if the new value is valid, that is in the current stack frame, and in the same page
if new_rsp >= init_rsp - 4096 && new_rsp <= init_rsp then
update_reg_64' rRsp new_rsp s
else
s
let cf (flags:flags_t) : flag_val_t =
flags fCarry
let overflow(flags:flags_t) : flag_val_t =
flags fOverflow
let update_cf' (flags:flags_t) (new_cf:bool) : (new_flags:flags_t{cf new_flags == Some new_cf}) =
FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fCarry then Some new_cf else flags f) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.HeapTypes_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.X64.Machine_Semantics_s.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "FStar.Seq.Base",
"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.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_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.HeapTypes_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | flags: Vale.X64.Machine_Semantics_s.flags_t -> new_of: Prims.bool
-> new_flags:
Vale.X64.Machine_Semantics_s.flags_t
{Vale.X64.Machine_Semantics_s.overflow new_flags == FStar.Pervasives.Native.Some new_of} | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.flags_t",
"Prims.bool",
"FStar.FunctionalExtensionality.on_dom",
"Vale.X64.Machine_s.flag",
"FStar.Pervasives.Native.option",
"Prims.op_Equality",
"Vale.X64.Machine_s.fOverflow",
"FStar.Pervasives.Native.Some",
"Prims.eq2",
"Vale.X64.Machine_Semantics_s.overflow"
] | [] | false | false | false | false | false | let update_of' (flags: flags_t) (new_of: bool)
: (new_flags: flags_t{overflow new_flags == Some new_of}) =
| FStar.FunctionalExtensionality.on_dom flag (fun f -> if f = fOverflow then Some new_of else flags f) | false |
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_5p | val uint8_5p : Type0 | let uint8_5p = uint8_1p & uint8_4p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 12,
"start_col": 0,
"start_line": 12
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *)
let uint8_2p = uint8_1p & uint8_1p
let uint8_3p = uint8_1p & uint8_2p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_1p",
"Hacl.Impl.SHA2.Types.uint8_4p"
] | [] | false | false | false | true | true | let uint8_5p =
| uint8_1p & uint8_4p | false |
|
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_2x4p | val uint8_2x4p : Type0 | let uint8_2x4p = uint8_4p & uint8_4p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 17,
"start_col": 0,
"start_line": 17
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *)
let uint8_2p = uint8_1p & uint8_1p
let uint8_3p = uint8_1p & uint8_2p
let uint8_4p = uint8_1p & uint8_3p
let uint8_5p = uint8_1p & uint8_4p
let uint8_6p = uint8_1p & uint8_5p
let uint8_7p = uint8_1p & uint8_6p
let uint8_8p = uint8_1p & uint8_7p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_4p"
] | [] | false | false | false | true | true | let uint8_2x4p =
| uint8_4p & uint8_4p | false |
|
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_7p | val uint8_7p : Type0 | let uint8_7p = uint8_1p & uint8_6p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 14,
"start_col": 0,
"start_line": 14
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *)
let uint8_2p = uint8_1p & uint8_1p
let uint8_3p = uint8_1p & uint8_2p
let uint8_4p = uint8_1p & uint8_3p
let uint8_5p = uint8_1p & uint8_4p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_1p",
"Hacl.Impl.SHA2.Types.uint8_6p"
] | [] | false | false | false | true | true | let uint8_7p =
| uint8_1p & uint8_6p | false |
|
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_8p | val uint8_8p : Type0 | let uint8_8p = uint8_1p & uint8_7p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *)
let uint8_2p = uint8_1p & uint8_1p
let uint8_3p = uint8_1p & uint8_2p
let uint8_4p = uint8_1p & uint8_3p
let uint8_5p = uint8_1p & uint8_4p
let uint8_6p = uint8_1p & uint8_5p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_1p",
"Hacl.Impl.SHA2.Types.uint8_7p"
] | [] | false | false | false | true | true | let uint8_8p =
| uint8_1p & uint8_7p | false |
|
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_2x8p | val uint8_2x8p : Type0 | let uint8_2x8p = uint8_8p & uint8_8p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 18,
"start_col": 0,
"start_line": 18
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *)
let uint8_2p = uint8_1p & uint8_1p
let uint8_3p = uint8_1p & uint8_2p
let uint8_4p = uint8_1p & uint8_3p
let uint8_5p = uint8_1p & uint8_4p
let uint8_6p = uint8_1p & uint8_5p
let uint8_7p = uint8_1p & uint8_6p
let uint8_8p = uint8_1p & uint8_7p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_8p"
] | [] | false | false | false | true | true | let uint8_2x8p =
| uint8_8p & uint8_8p | false |
|
Hacl.Impl.SHA2.Types.fst | Hacl.Impl.SHA2.Types.uint8_6p | val uint8_6p : Type0 | let uint8_6p = uint8_1p & uint8_5p | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module Hacl.Impl.SHA2.Types
inline_for_extraction noextract
let uint8_1p = LowStar.Buffer.buffer FStar.UInt8.t
(* This allows generating pretty names for several types used in SHA2-MB,
thus improving code quality. This also avoid an unpleasant dependency from
SHA2-128 to SHA2-256. See #523 for discussion. *)
let uint8_2p = uint8_1p & uint8_1p
let uint8_3p = uint8_1p & uint8_2p
let uint8_4p = uint8_1p & uint8_3p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Types.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.SHA2.Types.uint8_1p",
"Hacl.Impl.SHA2.Types.uint8_5p"
] | [] | false | false | false | true | true | let uint8_6p =
| uint8_1p & uint8_5p | false |
|
Pulse.Elaborate.fst | Pulse.Elaborate.elab_freevars_eq | val elab_freevars_eq (e: term) : Lemma (Set.equal (freevars e) (RT.freevars (elab_term e))) | val elab_freevars_eq (e: term) : Lemma (Set.equal (freevars e) (RT.freevars (elab_term e))) | let rec elab_freevars_eq (e:term)
: Lemma (Set.equal (freevars e) (RT.freevars (elab_term e))) =
match e.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_freevars_eq p
| Tm_Pure t -> elab_freevars_eq t
| Tm_AddInv l r
| Tm_Star l r ->
elab_freevars_eq l;
elab_freevars_eq r
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_freevars_eq t.binder_ty;
elab_freevars_eq body
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown
| Tm_FStar _ -> () | {
"file_name": "lib/steel/pulse/Pulse.Elaborate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 202,
"start_col": 0,
"start_line": 184
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Elaborate
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Elaborate.Core
// let rec elab_term_bv_sort (t:term)
// : Lemma
// (ensures
// (R.Tv_Var? (R.inspect_ln (elab_term t)) \/
// R.Tv_BVar? (R.inspect_ln (elab_term t))) ==>
// (match R.inspect_ln (elab_term t) with
// | R.Tv_Var bv
// | R.Tv_BVar bv ->
// let vv = R.inspect_bv bv in
// vv.bv_sort == RT.tun))
// = admit()
#push-options "--fuel 10 --ifuel 10 --z3rlimit_factor 30 --query_stats --z3cliopt 'smt.qi.eager_threshold=100'"
let rec elab_open_commute' (e:term)
(v:term)
(n:index)
: Lemma (ensures
RT.subst_term (elab_term e) [ RT.DT n (elab_term v) ] ==
elab_term (open_term' e v n))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
// | Tm_PureApp e1 _ e2 ->
// elab_open_commute' e1 v n;
// elab_open_commute' e2 v n
| Tm_Inv p ->
elab_open_commute' p v n
| Tm_Pure p ->
elab_open_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_open_commute' e1 v n;
elab_open_commute' e2 v n
| Tm_ExistsSL u t body
| Tm_ForallSL u t body ->
elab_open_commute' t.binder_ty v n;
elab_open_commute' body v (n + 1)
| Tm_FStar t -> ()
let elab_comp_open_commute' (c:comp) (v:term) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.DT n (elab_term v) ] ==
elab_comp (open_comp' c v n))
= match c with
| C_Tot t -> elab_open_commute' t v n
| C_ST s
| C_STGhost s ->
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_open_commute' inames v n;
elab_open_commute' s.res v n;
elab_open_commute' s.pre v n;
elab_open_commute' s.post v (n + 1)
let rec elab_close_commute' (e:term)
(v:var)
(n:index)
: Lemma (ensures (
RT.subst_term (elab_term e) [ RT.ND v n ] ==
elab_term (close_term' e v n)))
(decreases e)
= match e.t with
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_VProp
| Tm_Unknown -> ()
| Tm_Inv p ->
elab_close_commute' p v n
| Tm_Pure p ->
elab_close_commute' p v n
| Tm_AddInv e1 e2
| Tm_Star e1 e2 ->
elab_close_commute' e1 v n;
elab_close_commute' e2 v n
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_close_commute' t.binder_ty v n;
elab_close_commute' body v (n + 1)
| Tm_FStar _ -> ()
let elab_comp_close_commute' (c:comp) (v:var) (n:index)
: Lemma (ensures
RT.subst_term (elab_comp c) [ RT.ND v n ] ==
elab_comp (close_comp' c v n))
(decreases c)
= match c with
| C_Tot t -> elab_close_commute' t v n
| C_ST s
| C_STGhost s ->
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
| C_STAtomic inames _ s ->
elab_close_commute' inames v n;
elab_close_commute' s.res v n;
elab_close_commute' s.pre v n;
elab_close_commute' s.post v (n + 1)
let elab_open_commute (t:term) (x:var)
: Lemma (elab_term (open_term t x) == RT.open_term (elab_term t) x)
= RT.open_term_spec (elab_term t) x;
elab_open_commute' t (null_var x) 0
let elab_comp_close_commute (c:comp) (x:var)
: Lemma (elab_comp (close_comp c x) == RT.close_term (elab_comp c) x)
= RT.close_term_spec (elab_comp c) x;
elab_comp_close_commute' c x 0
let elab_comp_open_commute (c:comp) (x:term)
: Lemma (elab_comp (open_comp_with c x) == RT.open_with (elab_comp c) (elab_term x))
= RT.open_with_spec (elab_comp c) (elab_term x);
elab_comp_open_commute' c x 0
let rec elab_ln t i =
match t.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_ln p i
| Tm_Pure t -> elab_ln t i
| Tm_AddInv l r
| Tm_Star l r ->
elab_ln l i;
elab_ln r i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_ln t.binder_ty i;
elab_ln body (i + 1)
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown
| Tm_FStar _ -> ()
let elab_ln_comp (c:comp) (i:int)
: Lemma (requires ln_c' c i)
(ensures RT.ln' (elab_comp c) i) =
match c with
| C_Tot t -> elab_ln t i
| C_ST st
| C_STGhost st ->
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1)
| C_STAtomic inames _ st ->
elab_ln inames i;
elab_ln st.res i;
elab_ln st.pre i;
elab_ln st.post (i + 1) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Elaborate.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Naming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"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": 10,
"initial_ifuel": 10,
"max_fuel": 10,
"max_ifuel": 10,
"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.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 30,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Pulse.Syntax.Base.term
-> FStar.Pervasives.Lemma
(ensures
FStar.Set.equal (Pulse.Syntax.Naming.freevars e)
(FStar.Reflection.Typing.freevars (Pulse.Elaborate.Pure.elab_term e))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Elaborate.elab_freevars_eq",
"Prims.unit",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.host_term",
"Prims.l_True",
"Prims.squash",
"FStar.Set.equal",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.freevars",
"FStar.Reflection.Typing.freevars",
"Pulse.Elaborate.Pure.elab_term",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec elab_freevars_eq (e: term) : Lemma (Set.equal (freevars e) (RT.freevars (elab_term e))) =
| match e.t with
| Tm_Emp -> ()
| Tm_Inv p -> elab_freevars_eq p
| Tm_Pure t -> elab_freevars_eq t
| Tm_AddInv l r
| Tm_Star l r ->
elab_freevars_eq l;
elab_freevars_eq r
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
elab_freevars_eq t.binder_ty;
elab_freevars_eq body
| Tm_VProp | Tm_Inames | Tm_EmpInames | Tm_Unknown | Tm_FStar _ -> () | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.