effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let uint64_view = Vale.Interop.Views.up_view64
let uint64_view =
false
null
false
Vale.Interop.Views.up_view64
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Interop.Views.up_view64" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val uint64_view : LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt64.t
[]
Vale.X64.Memory.uint64_view
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt64.t
{ "end_col": 46, "end_line": 61, "start_col": 18, "start_line": 61 }
Prims.Tot
val loc_none : loc
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_none = M.loc_none
val loc_none : loc let loc_none =
false
null
false
M.loc_none
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "LowStar.Monotonic.Buffer.loc_none" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val loc_none : loc
[]
Vale.X64.Memory.loc_none
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.X64.Memory.loc
{ "end_col": 25, "end_line": 80, "start_col": 15, "start_line": 80 }
Prims.GTot
val loc_union (s1 s2:loc) : GTot loc
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_union = M.loc_union
val loc_union (s1 s2:loc) : GTot loc let loc_union =
false
null
false
M.loc_union
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "LowStar.Monotonic.Buffer.loc_union" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val loc_union (s1 s2:loc) : GTot loc
[]
Vale.X64.Memory.loc_union
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s1: Vale.X64.Memory.loc -> s2: Vale.X64.Memory.loc -> Prims.GTot Vale.X64.Memory.loc
{ "end_col": 27, "end_line": 81, "start_col": 16, "start_line": 81 }
Prims.GTot
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_buffer #t b = M.loc_buffer b.bsrc
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc let loc_buffer #t b =
false
null
false
M.loc_buffer b.bsrc
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "LowStar.Monotonic.Buffer.loc_buffer", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.X64.Memory.loc" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val loc_buffer (#t:base_typ) (b:buffer t) : GTot loc
[]
Vale.X64.Memory.loc_buffer
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t -> Prims.GTot Vale.X64.Memory.loc
{ "end_col": 41, "end_line": 82, "start_col": 22, "start_line": 82 }
Prims.GTot
val loc_includes (s1 s2:loc) : GTot prop0
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_includes = M.loc_includes
val loc_includes (s1 s2:loc) : GTot prop0 let loc_includes =
false
null
false
M.loc_includes
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "LowStar.Monotonic.Buffer.loc_includes" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val loc_includes (s1 s2:loc) : GTot prop0
[]
Vale.X64.Memory.loc_includes
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s1: Vale.X64.Memory.loc -> s2: Vale.X64.Memory.loc -> Prims.GTot Vale.Def.Prop_s.prop0
{ "end_col": 33, "end_line": 84, "start_col": 19, "start_line": 84 }
Prims.GTot
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int let buffer_addr #t b h =
false
null
false
IB.addrs_of_mem (_ih h) b
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Vale.Arch.HeapImpl.vale_heap", "Vale.Interop.Heap_s.addrs_of_mem", "Vale.Arch.HeapImpl._ih", "Prims.int" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val buffer_addr (#t:base_typ) (b:buffer t) (h:vale_heap) : GTot int
[]
Vale.X64.Memory.buffer_addr
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.int
{ "end_col": 50, "end_line": 92, "start_col": 25, "start_line": 92 }
Prims.GTot
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0 let modifies s h h' =
false
null
false
M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "Prims.eq2", "FStar.Pervasives.Native.option", "Vale.Arch.HeapImpl.heaplet_id", "Vale.Arch.HeapImpl.__proj__ValeHeap__item__heapletId", "Prims.list", "Vale.Interop.Types.b8", "Prims.l_or", "Vale.Interop.Heap_s.list_disjoint_or_eq", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Interop.Types.addr_map", "Vale.Interop.Heap_s.mk_addr_map", "Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs", "FStar.HyperStack.ST.equal_domains", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val modifies (s:loc) (h1 h2:vale_heap) : GTot prop0
[]
Vale.X64.Memory.modifies
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Vale.Def.Prop_s.prop0
{ "end_col": 42, "end_line": 90, "start_col": 2, "start_line": 86 }
FStar.Pervasives.Lemma
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma (requires loc_disjoint (loc_buffer b) p /\ buffer_readable h b /\ modifies p h h' ) (ensures buffer_readable h b /\ buffer_readable h' b /\ buffer_as_seq h b == buffer_as_seq h' b ) [SMTPatOr [ [SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]; [SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)]; ]]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma (requires loc_disjoint (loc_buffer b) p /\ buffer_readable h b /\ modifies p h h' ) (ensures buffer_readable h b /\ buffer_readable h' b /\ buffer_as_seq h b == buffer_as_seq h' b ) [SMTPatOr [ [SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]; [SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)]; ]] let modifies_buffer_elim #t1 b p h h' =
false
null
true
let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b))
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "Prims._assert", "FStar.Seq.Base.equal", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.X64.Memory.buffer_as_seq", "Prims.unit", "Vale.X64.Memory.same_underlying_seq", "Vale.Lib.BufferViewHelpers.lemma_dv_equal", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "FStar.UInt8.t", "Vale.Interop.Types.down_view", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_buffer_elim (#t1:base_typ) (b:buffer t1) (p:loc) (h h':vale_heap) : Lemma (requires loc_disjoint (loc_buffer b) p /\ buffer_readable h b /\ modifies p h h' ) (ensures buffer_readable h b /\ buffer_readable h' b /\ buffer_as_seq h b == buffer_as_seq h' b ) [SMTPatOr [ [SMTPat (modifies p h h'); SMTPat (buffer_readable h' b)]; [SMTPat (modifies p h h'); SMTPat (buffer_as_seq h' b)]; ]]
[]
Vale.X64.Memory.modifies_buffer_elim
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t1 -> p: Vale.X64.Memory.loc -> h: Vale.Arch.HeapImpl.vale_heap -> h': Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.loc_disjoint (Vale.X64.Memory.loc_buffer b) p /\ Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.modifies p h h') (ensures Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.buffer_readable h' b /\ Vale.X64.Memory.buffer_as_seq h b == Vale.X64.Memory.buffer_as_seq h' b) [ SMTPatOr [ [ SMTPat (Vale.X64.Memory.modifies p h h'); SMTPat (Vale.X64.Memory.buffer_readable h' b) ]; [SMTPat (Vale.X64.Memory.modifies p h h'); SMTPat (Vale.X64.Memory.buffer_as_seq h' b)] ] ]
{ "end_col": 61, "end_line": 228, "start_col": 39, "start_line": 224 }
Prims.GTot
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool let valid_mem128 ptr h =
false
null
false
valid_mem_aux (TUInt128) ptr (_ih h).ptrs h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.valid_mem_aux", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.bool" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = ()
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool
[]
Vale.X64.Memory.valid_mem128
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
{ "end_col": 68, "end_line": 491, "start_col": 25, "start_line": 491 }
FStar.Pervasives.Lemma
val loc_includes_union_l_buffer (#t:base_typ) (s1 s2:loc) (b:buffer t) : Lemma (requires (loc_includes s1 (loc_buffer b) \/ loc_includes s2 (loc_buffer b))) (ensures (loc_includes (loc_union s1 s2) (loc_buffer b))) [SMTPat (loc_includes (loc_union s1 s2) (loc_buffer b))]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
val loc_includes_union_l_buffer (#t:base_typ) (s1 s2:loc) (b:buffer t) : Lemma (requires (loc_includes s1 (loc_buffer b) \/ loc_includes s2 (loc_buffer b))) (ensures (loc_includes (loc_union s1 s2) (loc_buffer b))) [SMTPat (loc_includes (loc_union s1 s2) (loc_buffer b))] let loc_includes_union_l_buffer #t s1 s2 b =
false
null
true
M.loc_includes_union_l s1 s2 (loc_buffer b)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.loc", "Vale.X64.Memory.buffer", "LowStar.Monotonic.Buffer.loc_includes_union_l", "Vale.X64.Memory.loc_buffer", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_includes_union_l_buffer (#t:base_typ) (s1 s2:loc) (b:buffer t) : Lemma (requires (loc_includes s1 (loc_buffer b) \/ loc_includes s2 (loc_buffer b))) (ensures (loc_includes (loc_union s1 s2) (loc_buffer b))) [SMTPat (loc_includes (loc_union s1 s2) (loc_buffer b))]
[]
Vale.X64.Memory.loc_includes_union_l_buffer
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s1: Vale.X64.Memory.loc -> s2: Vale.X64.Memory.loc -> b: Vale.X64.Memory.buffer t -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.loc_includes s1 (Vale.X64.Memory.loc_buffer b) \/ Vale.X64.Memory.loc_includes s2 (Vale.X64.Memory.loc_buffer b)) (ensures Vale.X64.Memory.loc_includes (Vale.X64.Memory.loc_union s1 s2) (Vale.X64.Memory.loc_buffer b)) [ SMTPat (Vale.X64.Memory.loc_includes (Vale.X64.Memory.loc_union s1 s2) (Vale.X64.Memory.loc_buffer b)) ]
{ "end_col": 88, "end_line": 239, "start_col": 45, "start_line": 239 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) = let bs = layout.vl_buffers in modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap (forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)} layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i) ) /\ (forall (i:heaplet_id).{:pattern (Map16.sel hs i)} inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\ (forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==> inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\ (forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)} i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\ True
let inv_heaplets (layout: vale_heap_layout_inner) (h: vale_heap) (hs: vale_heaplets) (mt: memTaint_t) =
false
null
false
let bs = layout.vl_buffers in modifies layout.vl_mod_loc layout.vl_old_heap h /\ (forall (i: heaplet_id) (a: int). {:pattern Set.mem a (layout.vl_heaplet_sets i)} layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i)) /\ (forall (i: heaplet_id). {:pattern (Map16.sel hs i)} inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\ (forall (i: nat). {:pattern (Seq.index bs i)} i < Seq.length bs ==> inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\ (forall (i1: nat) (i2: nat). {:pattern (Seq.index bs i1); (Seq.index bs i2)} i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\ True
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapImpl.vale_heap_layout_inner", "Vale.Arch.HeapImpl.vale_heap", "Vale.Arch.HeapImpl.vale_heaplets", "Vale.Arch.HeapTypes_s.memTaint_t", "Prims.l_and", "Vale.X64.Memory.modifies", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_mod_loc", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap", "Prims.l_Forall", "Vale.Arch.HeapImpl.heaplet_id", "Prims.int", "Prims.l_iff", "Prims.eq2", "FStar.Pervasives.Native.option", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplet_map", "FStar.Pervasives.Native.Some", "Prims.b2t", "FStar.Set.mem", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplet_sets", "Vale.X64.Memory.inv_heaplet", "Vale.Lib.Map16.sel", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Arch.HeapImpl.buffer_info", "Vale.X64.Memory.inv_buffer_info", "FStar.Seq.Base.index", "Vale.X64.Memory.buffer_info_disjoint", "Prims.l_True", "FStar.Seq.Base.seq", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i let inv_heaplet (owns:Set.set int) (h hi:vale_heap) = h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True ) /\ True // heaplet state matches heap state let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) = let t = bi.bi_typ in let hid = bi.bi_heaplet in let hi = Map16.get hs hid in let b = bi.bi_buffer in let owns = owners hid in (bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\ buffer_as_seq hi b == buffer_as_seq h b /\ (valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\ (forall (i:int).{:pattern Set.mem i owns} buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\ True
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inv_heaplets : layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> h: Vale.Arch.HeapImpl.vale_heap -> hs: Vale.Arch.HeapImpl.vale_heaplets -> mt: Vale.Arch.HeapTypes_s.memTaint_t -> Prims.logical
[]
Vale.X64.Memory.inv_heaplets
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> h: Vale.Arch.HeapImpl.vale_heap -> hs: Vale.Arch.HeapImpl.vale_heaplets -> mt: Vale.Arch.HeapTypes_s.memTaint_t -> Prims.logical
{ "end_col": 6, "end_line": 736, "start_col": 99, "start_line": 724 }
Prims.GTot
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t)) let buffer_as_seq #t h b =
false
null
false
let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.buffer", "Vale.Lib.Seqs_s.seq_map", "Vale.Interop.Types.base_typ_as_type", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.X64.Memory.v_to_typ", "FStar.Seq.Properties.lseq", "LowStar.BufferView.Up.length", "LowStar.BufferView.Up.mk_buffer", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.X64.Memory.uint_view", "LowStar.BufferView.Up.as_seq", "Vale.Interop.Heap_s.hs_of_mem", "Vale.Arch.HeapImpl._ih", "FStar.Seq.Base.seq" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val buffer_as_seq (#t:base_typ) (h:vale_heap) (b:buffer t) : GTot (Seq.seq (base_typ_as_vale_type t))
[]
Vale.X64.Memory.buffer_as_seq
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Arch.HeapImpl.vale_heap -> b: Vale.X64.Memory.buffer t -> Prims.GTot (FStar.Seq.Base.seq (Vale.X64.Memory.base_typ_as_vale_type t))
{ "end_col": 40, "end_line": 74, "start_col": 26, "start_line": 72 }
FStar.Pervasives.Lemma
val modifies_goal_directed_trans2 (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma (requires modifies s12 h1 h2 /\ modifies_goal_directed s13 h2 h3 /\ loc_includes s13 s12 ) (ensures (modifies_goal_directed s13 h1 h3)) [SMTPat (modifies s12 h1 h2); SMTPat (modifies_goal_directed s13 h1 h3)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
val modifies_goal_directed_trans2 (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma (requires modifies s12 h1 h2 /\ modifies_goal_directed s13 h2 h3 /\ loc_includes s13 s12 ) (ensures (modifies_goal_directed s13 h1 h3)) [SMTPat (modifies s12 h1 h2); SMTPat (modifies_goal_directed s13 h1 h3)] let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 =
false
null
true
modifies_goal_directed_trans s12 h1 h2 s13 h3
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.modifies_goal_directed_trans", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); ()
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_goal_directed_trans2 (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma (requires modifies s12 h1 h2 /\ modifies_goal_directed s13 h2 h3 /\ loc_includes s13 s12 ) (ensures (modifies_goal_directed s13 h1 h3)) [SMTPat (modifies s12 h1 h2); SMTPat (modifies_goal_directed s13 h1 h3)]
[]
Vale.X64.Memory.modifies_goal_directed_trans2
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s12: Vale.X64.Memory.loc -> h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> s13: Vale.X64.Memory.loc -> h3: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies s12 h1 h2 /\ Vale.X64.Memory.modifies_goal_directed s13 h2 h3 /\ Vale.X64.Memory.loc_includes s13 s12) (ensures Vale.X64.Memory.modifies_goal_directed s13 h1 h3) [ SMTPat (Vale.X64.Memory.modifies s12 h1 h2); SMTPat (Vale.X64.Memory.modifies_goal_directed s13 h1 h3) ]
{ "end_col": 98, "end_line": 251, "start_col": 53, "start_line": 251 }
FStar.Pervasives.Lemma
val loc_includes_none (s:loc) : Lemma (loc_includes s loc_none) [SMTPat (loc_includes s loc_none)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_includes_none s = M.loc_includes_none s
val loc_includes_none (s:loc) : Lemma (loc_includes s loc_none) [SMTPat (loc_includes s loc_none)] let loc_includes_none s =
false
null
true
M.loc_includes_none s
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "LowStar.Monotonic.Buffer.loc_includes_none", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_includes_none (s:loc) : Lemma (loc_includes s loc_none) [SMTPat (loc_includes s loc_none)]
[]
Vale.X64.Memory.loc_includes_none
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (ensures Vale.X64.Memory.loc_includes s Vale.X64.Memory.loc_none) [SMTPat (Vale.X64.Memory.loc_includes s Vale.X64.Memory.loc_none)]
{ "end_col": 47, "end_line": 240, "start_col": 26, "start_line": 240 }
Prims.Tot
val uint_view (t: base_typ) : (v: UV.view UInt8.t (IB.base_typ_as_type t) {UV.View?.n v == view_n t})
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view
val uint_view (t: base_typ) : (v: UV.view UInt8.t (IB.base_typ_as_type t) {UV.View?.n v == view_n t}) let uint_view (t: base_typ) : (v: UV.view UInt8.t (IB.base_typ_as_type t) {UV.View?.n v == view_n t}) =
false
null
false
match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.uint8_view", "Vale.X64.Memory.uint16_view", "Vale.X64.Memory.uint32_view", "Vale.X64.Memory.uint64_view", "Vale.X64.Memory.uint128_view", "LowStar.BufferView.Up.view", "FStar.UInt8.t", "Vale.Interop.Types.base_typ_as_type", "Prims.eq2", "Prims.pos", "LowStar.BufferView.Up.__proj__View__item__n", "Vale.Interop.Types.view_n" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val uint_view (t: base_typ) : (v: UV.view UInt8.t (IB.base_typ_as_type t) {UV.View?.n v == view_n t})
[]
Vale.X64.Memory.uint_view
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> v: LowStar.BufferView.Up.view FStar.UInt8.t (Vale.Interop.Types.base_typ_as_type t) {View?.n v == Vale.Interop.Types.view_n t}
{ "end_col": 28, "end_line": 70, "start_col": 2, "start_line": 65 }
Prims.Tot
val v_of_typ (t: base_typ) (v: base_typ_as_vale_type t) : base_typ_as_type t
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v
val v_of_typ (t: base_typ) (v: base_typ_as_vale_type t) : base_typ_as_type t let v_of_typ (t: base_typ) (v: base_typ_as_vale_type t) : base_typ_as_type t =
false
null
false
match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.base_typ_as_vale_type", "FStar.UInt8.uint_to_t", "FStar.UInt16.uint_to_t", "FStar.UInt32.uint_to_t", "FStar.UInt64.uint_to_t", "Vale.Interop.Types.base_typ_as_type" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val v_of_typ (t: base_typ) (v: base_typ_as_vale_type t) : base_typ_as_type t
[]
Vale.X64.Memory.v_of_typ
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> v: Vale.X64.Memory.base_typ_as_vale_type t -> Vale.Interop.Types.base_typ_as_type t
{ "end_col": 17, "end_line": 42, "start_col": 2, "start_line": 37 }
Prims.GTot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h
let writeable_mem (t: base_typ) addr (h: vale_heap) =
false
null
false
writeable_mem_aux t addr (_ih h).ptrs h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.writeable_mem_aux", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.bool" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val writeable_mem : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
[]
Vale.X64.Memory.writeable_mem
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
{ "end_col": 91, "end_line": 409, "start_col": 52, "start_line": 409 }
Prims.Tot
val v_to_typ (t: base_typ) (v: base_typ_as_type t) : base_typ_as_vale_type t
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v
val v_to_typ (t: base_typ) (v: base_typ_as_type t) : base_typ_as_vale_type t let v_to_typ (t: base_typ) (v: base_typ_as_type t) : base_typ_as_vale_type t =
false
null
false
match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.Interop.Types.base_typ_as_type", "FStar.UInt8.v", "FStar.UInt16.v", "FStar.UInt32.v", "FStar.UInt64.v", "Vale.X64.Memory.base_typ_as_vale_type" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val v_to_typ (t: base_typ) (v: base_typ_as_type t) : base_typ_as_vale_type t
[]
Vale.X64.Memory.v_to_typ
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> v: Vale.Interop.Types.base_typ_as_type t -> Vale.X64.Memory.base_typ_as_vale_type t
{ "end_col": 17, "end_line": 50, "start_col": 2, "start_line": 45 }
Prims.Ghost
val writeable_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)\/buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
val writeable_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)\/buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) let rec writeable_mem_aux (t: base_typ) addr (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)\/buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) =
false
null
false
match ps with | [] -> false | a :: q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Prims.list", "Vale.X64.Memory.b8", "Vale.Arch.HeapImpl.vale_heap", "Prims.op_BarBar", "Vale.X64.Memory.writeable_buffer", "Vale.X64.Memory.writeable_mem_aux", "Prims.bool", "Vale.X64.Memory.sub_list", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.l_iff", "Prims.b2t", "Prims.l_Exists", "Vale.X64.Memory.buffer", "Prims.l_and", "FStar.List.Tot.Base.memP", "Vale.X64.Memory.valid_buffer", "Vale.X64.Memory.buffer_writeable" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val writeable_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)\/buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x))
[ "recursion" ]
Vale.X64.Memory.writeable_mem_aux
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> ps: Prims.list Vale.X64.Memory.b8 -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost Prims.bool
{ "end_col": 71, "end_line": 408, "start_col": 2, "start_line": 406 }
Prims.Tot
val valid_layout_buffer_id (t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h_id:option heaplet_id) (write:bool) : prop0
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write
val valid_layout_buffer_id (t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h_id:option heaplet_id) (write:bool) : prop0 let valid_layout_buffer_id t b layout h_id write =
false
null
false
match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Vale.Arch.HeapImpl.vale_heap_layout", "FStar.Pervasives.Native.option", "Vale.Arch.HeapImpl.heaplet_id", "Prims.bool", "Prims.l_True", "Prims.l_and", "Prims.b2t", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner", "Vale.X64.Memory.valid_layout_data_buffer", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"]
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_layout_buffer_id (t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h_id:option heaplet_id) (write:bool) : prop0
[]
Vale.X64.Memory.valid_layout_buffer_id
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> b: Vale.X64.Memory.buffer t -> layout: Vale.Arch.HeapImpl.vale_heap_layout -> h_id: FStar.Pervasives.Native.option Vale.Arch.HeapImpl.heaplet_id -> write: Prims.bool -> Vale.Def.Prop_s.prop0
{ "end_col": 58, "end_line": 693, "start_col": 2, "start_line": 689 }
Prims.Ghost
val get_addr_ptr (t: base_typ) (ptr: int) (h: vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h)
val get_addr_ptr (t: base_typ) (ptr: int) (h: vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) let get_addr_ptr (t: base_typ) (ptr: int) (h: vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) =
false
null
false
Some?.v (find_valid_buffer t ptr h)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "FStar.Pervasives.Native.__proj__Some__item__v", "Vale.X64.Memory.buffer", "Vale.X64.Memory.find_valid_buffer", "Prims.b2t", "Vale.X64.Memory.valid_mem", "Prims.l_and", "FStar.List.Tot.Base.memP", "Vale.Interop.Types.b8", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Vale.X64.Memory.valid_buffer" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_addr_ptr (t: base_typ) (ptr: int) (h: vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h)
[]
Vale.X64.Memory.get_addr_ptr
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost (Vale.X64.Memory.buffer t)
{ "end_col": 37, "end_line": 450, "start_col": 2, "start_line": 450 }
Prims.Ghost
val store_mem (t: base_typ) (addr: int) (v: base_typ_as_vale_type t) (h: vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
val store_mem (t: base_typ) (addr: int) (v: base_typ_as_vale_type t) (h: vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) let store_mem (t: base_typ) (addr: int) (v: base_typ_as_vale_type t) (h: vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) =
false
null
false
match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.find_writeable_buffer", "Vale.X64.Memory.buffer", "Vale.X64.Memory.buffer_write", "Vale.X64.Memory.get_addr_in_ptr", "Vale.X64.Memory.buffer_length", "Vale.X64.Memory.buffer_addr", "Prims.l_True", "Prims.l_and", "Prims.eq2", "Vale.Interop.Types.addr_map", "Prims.l_or", "Vale.Interop.Heap_s.mk_addr_map", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs", "Prims.list", "Vale.Interop.Types.b8", "Vale.Interop.Heap_s.list_disjoint_or_eq" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val store_mem (t: base_typ) (addr: int) (v: base_typ_as_vale_type t) (h: vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs)
[]
Vale.X64.Memory.store_mem
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> v: Vale.X64.Memory.base_typ_as_vale_type t -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost Vale.Arch.HeapImpl.vale_heap
{ "end_col": 72, "end_line": 471, "start_col": 2, "start_line": 467 }
FStar.Pervasives.Lemma
val index128_get_heap_val128_aux (s: Seq.lseq UInt8.t 16) (ptr: int) (heap: S.machine_heap) : Lemma (requires (forall (j: nat). j < 16 ==> UInt8.v (Seq.index s j) == heap.[ ptr + j ])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr + 4) heap) (S.get_heap_val32 (ptr + 8) heap) (S.get_heap_val32 (ptr + 12) heap))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
val index128_get_heap_val128_aux (s: Seq.lseq UInt8.t 16) (ptr: int) (heap: S.machine_heap) : Lemma (requires (forall (j: nat). j < 16 ==> UInt8.v (Seq.index s j) == heap.[ ptr + j ])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr + 4) heap) (S.get_heap_val32 (ptr + 8) heap) (S.get_heap_val32 (ptr + 12) heap)) let index128_get_heap_val128_aux (s: Seq.lseq UInt8.t 16) (ptr: int) (heap: S.machine_heap) : Lemma (requires (forall (j: nat). j < 16 ==> UInt8.v (Seq.index s j) == heap.[ ptr + j ])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr + 4) heap) (S.get_heap_val32 (ptr + 8) heap) (S.get_heap_val32 (ptr + 12) heap)) =
false
null
true
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal ()
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "FStar.Seq.Properties.lseq", "FStar.UInt8.t", "Prims.int", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Def.Types_s.le_bytes_to_quad32_reveal", "Prims.unit", "Vale.Interop.Views.get128_reveal", "Vale.Arch.MachineHeap_s.get_heap_val32_reveal", "FStar.Pervasives.reveal_opaque", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat8", "Prims.eq2", "Prims.op_Modulus", "FStar.Seq.Base.length", "Vale.Def.Words_s.four", "Prims.op_Division", "Vale.Def.Words.Seq_s.seq_to_seq_four_LE", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Prims.l_or", "FStar.UInt.size", "FStar.UInt8.n", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Vale.Def.Words_s.pow2_8", "FStar.UInt8.v", "FStar.Seq.Base.index", "Vale.X64.Memory.op_String_Access", "Prims.op_Addition", "Prims.squash", "Vale.Def.Types_s.nat32", "Vale.Interop.Views.get128", "Vale.Def.Words_s.Mkfour", "Vale.Arch.MachineHeap_s.get_heap_val32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val index128_get_heap_val128_aux (s: Seq.lseq UInt8.t 16) (ptr: int) (heap: S.machine_heap) : Lemma (requires (forall (j: nat). j < 16 ==> UInt8.v (Seq.index s j) == heap.[ ptr + j ])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr + 4) heap) (S.get_heap_val32 (ptr + 8) heap) (S.get_heap_val32 (ptr + 12) heap))
[]
Vale.X64.Memory.index128_get_heap_val128_aux
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Properties.lseq FStar.UInt8.t 16 -> ptr: Prims.int -> heap: Vale.Arch.MachineHeap_s.machine_heap -> FStar.Pervasives.Lemma (requires forall (j: Prims.nat). j < 16 ==> FStar.UInt8.v (FStar.Seq.Base.index s j) == heap.[ ptr + j ]) (ensures Vale.Interop.Views.get128 s == Vale.Def.Words_s.Mkfour (Vale.Arch.MachineHeap_s.get_heap_val32 ptr heap) (Vale.Arch.MachineHeap_s.get_heap_val32 (ptr + 4) heap) (Vale.Arch.MachineHeap_s.get_heap_val32 (ptr + 8) heap) (Vale.Arch.MachineHeap_s.get_heap_val32 (ptr + 12) heap))
{ "end_col": 47, "end_line": 163, "start_col": 2, "start_line": 160 }
FStar.Pervasives.Lemma
val valid_memtaint (mem: vale_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
val valid_memtaint (mem: vale_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) let rec valid_memtaint (mem: vale_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) =
false
null
true
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapImpl.vale_heap", "Prims.list", "Vale.X64.Memory.b8", "Vale.Arch.HeapTypes_s.taint", "Vale.Def.Opaque_s.opaque_assert", "Vale.Interop.Types.b8", "Prims.logical", "Vale.Interop.Heap_s.list_disjoint_or_eq", "Vale.Interop.Heap_s.list_disjoint_or_eq_def", "Prims.l_Forall", "Prims.l_imp", "FStar.List.Tot.Base.memP", "Vale.Interop.Heap_s.disjoint_or_eq_b8", "Prims.unit", "Vale.X64.Memory.write_taint_lemma", "Vale.Arch.HeapImpl._ih", "Vale.Interop.Base.create_memtaint", "Prims._assert", "Prims.eq2", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.Interop.Base.write_taint", "Vale.X64.Memory.valid_memtaint", "FStar.Pervasives.reveal_opaque", "Vale.Def.Words_s.nat64", "Vale.Interop.Types.addr_map_pred", "Prims.squash", "Vale.X64.Memory.valid_taint_bufs", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_memtaint (mem: vale_heap) (ps: list b8) (ts: (b8 -> GTot taint)) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts)
[ "recursion" ]
Vale.X64.Memory.valid_memtaint
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mem: Vale.Arch.HeapImpl.vale_heap -> ps: Prims.list Vale.X64.Memory.b8 -> ts: (_: Vale.X64.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint) -> FStar.Pervasives.Lemma (requires Vale.Interop.Heap_s.list_disjoint_or_eq ps) (ensures Vale.X64.Memory.valid_taint_bufs mem (Vale.Interop.Base.create_memtaint (Vale.Arch.HeapImpl._ih mem) ps ts) ps ts)
{ "end_col": 142, "end_line": 677, "start_col": 2, "start_line": 666 }
FStar.Pervasives.Lemma
val lemma_store_mem128 (b:buffer128) (i:nat) (v:quad32) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem128 (buffer_addr b h + scale16 i) v h == buffer_write b i v h )
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h
val lemma_store_mem128 (b:buffer128) (i:nat) (v:quad32) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem128 (buffer_addr b h + scale16 i) v h == buffer_write b i v h ) let lemma_store_mem128 b i v h =
false
null
true
lemma_store_mem TUInt128 b i v h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.buffer128", "Prims.nat", "Vale.Def.Types_s.quad32", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.lemma_store_mem", "Vale.Arch.HeapTypes_s.TUInt128", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b)
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_store_mem128 (b:buffer128) (i:nat) (v:quad32) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem128 (buffer_addr b h + scale16 i) v h == buffer_write b i v h )
[]
Vale.X64.Memory.lemma_store_mem128
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer128 -> i: Prims.nat -> v: Vale.Def.Types_s.quad32 -> h: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\ Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.buffer_writeable b) (ensures Vale.X64.Memory.store_mem128 (Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale16 i) v h == Vale.X64.Memory.buffer_write b i v h)
{ "end_col": 65, "end_line": 558, "start_col": 33, "start_line": 558 }
FStar.Pervasives.Lemma
val index64_heap_aux (s: Seq.lseq UInt8.t 8) (heap: S.machine_heap) (ptr: int) : Lemma (requires forall (j: nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ ptr + j ]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap)
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
val index64_heap_aux (s: Seq.lseq UInt8.t 8) (heap: S.machine_heap) (ptr: int) : Lemma (requires forall (j: nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ ptr + j ]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) let index64_heap_aux (s: Seq.lseq UInt8.t 8) (heap: S.machine_heap) (ptr: int) : Lemma (requires forall (j: nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ ptr + j ]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) =
false
null
true
let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal ()
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "FStar.Seq.Properties.lseq", "FStar.UInt8.t", "Vale.Arch.MachineHeap_s.machine_heap", "Prims.int", "Vale.Def.Types_s.le_bytes_to_nat64_reveal", "Prims.unit", "Vale.Arch.MachineHeap_s.get_heap_val64_reveal", "Vale.Interop.Views.get64_reveal", "FStar.Pervasives.reveal_opaque", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat8", "Prims.eq2", "Prims.op_Modulus", "FStar.Seq.Base.length", "Vale.Def.Words_s.four", "Prims.op_Division", "Vale.Def.Words.Seq_s.seq_to_seq_four_LE", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_or", "FStar.UInt.size", "FStar.UInt8.n", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Vale.Def.Words_s.pow2_8", "FStar.UInt8.v", "FStar.Seq.Base.index", "Vale.X64.Memory.op_String_Access", "Vale.Def.Types_s.nat8", "Prims.op_Addition", "Prims.squash", "FStar.UInt64.n", "Vale.Def.Words_s.pow2_64", "FStar.UInt64.v", "Vale.Interop.Views.get64", "Vale.Arch.MachineHeap_s.get_heap_val64", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j])
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val index64_heap_aux (s: Seq.lseq UInt8.t 8) (heap: S.machine_heap) (ptr: int) : Lemma (requires forall (j: nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ ptr + j ]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap)
[]
Vale.X64.Memory.index64_heap_aux
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Properties.lseq FStar.UInt8.t 8 -> heap: Vale.Arch.MachineHeap_s.machine_heap -> ptr: Prims.int -> FStar.Pervasives.Lemma (requires forall (j: Prims.nat{j < 8}). FStar.UInt8.v (FStar.Seq.Base.index s j) == heap.[ ptr + j ]) (ensures FStar.UInt64.v (Vale.Interop.Views.get64 s) == Vale.Arch.MachineHeap_s.get_heap_val64 ptr heap)
{ "end_col": 46, "end_line": 105, "start_col": 2, "start_line": 101 }
Prims.Tot
val scale_t (t: base_typ) (index: int) : int
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index
val scale_t (t: base_typ) (index: int) : int let scale_t (t: base_typ) (index: int) : int =
false
null
false
scale_by (view_n t) index
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.X64.Memory.scale_by", "Vale.Interop.Types.view_n" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val scale_t (t: base_typ) (index: int) : int
[]
Vale.X64.Memory.scale_t
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> index: Prims.int -> Prims.int
{ "end_col": 77, "end_line": 310, "start_col": 52, "start_line": 310 }
Prims.GTot
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat let buffer_length #t b =
false
null
false
UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t))
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "LowStar.BufferView.Up.length", "Vale.Interop.Types.base_typ_as_type", "LowStar.BufferView.Up.mk_buffer", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.X64.Memory.uint_view", "Prims.nat" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h))
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "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" }
null
val buffer_length (#t:base_typ) (b:buffer t) : GTot nat
[]
Vale.X64.Memory.buffer_length
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t -> Prims.GTot Prims.nat
{ "end_col": 85, "end_line": 78, "start_col": 25, "start_line": 78 }
FStar.Pervasives.Lemma
val loc_disjoint_union_r (s s1 s2:loc) : Lemma (requires (loc_disjoint s s1 /\ loc_disjoint s s2)) (ensures (loc_disjoint s (loc_union s1 s2))) [SMTPat (loc_disjoint s (loc_union s1 s2))]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
val loc_disjoint_union_r (s s1 s2:loc) : Lemma (requires (loc_disjoint s s1 /\ loc_disjoint s s2)) (ensures (loc_disjoint s (loc_union s1 s2))) [SMTPat (loc_disjoint s (loc_union s1 s2))] let loc_disjoint_union_r s s1 s2 =
false
null
true
M.loc_disjoint_union_r s s1 s2
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "LowStar.Monotonic.Buffer.loc_disjoint_union_r", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = ()
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_disjoint_union_r (s s1 s2:loc) : Lemma (requires (loc_disjoint s s1 /\ loc_disjoint s s2)) (ensures (loc_disjoint s (loc_union s1 s2))) [SMTPat (loc_disjoint s (loc_union s1 s2))]
[]
Vale.X64.Memory.loc_disjoint_union_r
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> s1: Vale.X64.Memory.loc -> s2: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.loc_disjoint s s1 /\ Vale.X64.Memory.loc_disjoint s s2) (ensures Vale.X64.Memory.loc_disjoint s (Vale.X64.Memory.loc_union s1 s2)) [SMTPat (Vale.X64.Memory.loc_disjoint s (Vale.X64.Memory.loc_union s1 s2))]
{ "end_col": 65, "end_line": 234, "start_col": 35, "start_line": 234 }
FStar.Pervasives.Lemma
val loc_disjoint_none_r (s:loc) : Lemma (ensures (loc_disjoint s loc_none)) [SMTPat (loc_disjoint s loc_none)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_disjoint_none_r s = M.loc_disjoint_none_r s
val loc_disjoint_none_r (s:loc) : Lemma (ensures (loc_disjoint s loc_none)) [SMTPat (loc_disjoint s loc_none)] let loc_disjoint_none_r s =
false
null
true
M.loc_disjoint_none_r s
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "LowStar.Monotonic.Buffer.loc_disjoint_none_r", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = ()
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_disjoint_none_r (s:loc) : Lemma (ensures (loc_disjoint s loc_none)) [SMTPat (loc_disjoint s loc_none)]
[]
Vale.X64.Memory.loc_disjoint_none_r
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (ensures Vale.X64.Memory.loc_disjoint s Vale.X64.Memory.loc_none) [SMTPat (Vale.X64.Memory.loc_disjoint s Vale.X64.Memory.loc_none)]
{ "end_col": 51, "end_line": 233, "start_col": 28, "start_line": 233 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
let sub_list (p1 p2: list 'a) =
false
null
false
forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Prims.list", "Prims.l_Forall", "Prims.l_imp", "FStar.List.Tot.Base.memP", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sub_list : p1: Prims.list 'a -> p2: Prims.list 'a -> Prims.logical
[]
Vale.X64.Memory.sub_list
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p1: Prims.list 'a -> p2: Prims.list 'a -> Prims.logical
{ "end_col": 100, "end_line": 348, "start_col": 31, "start_line": 348 }
FStar.Pervasives.Lemma
val find_valid_buffer_aux_ps (t: base_typ) (addr: int) (ps: list b8) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2
val find_valid_buffer_aux_ps (t: base_typ) (addr: int) (ps: list b8) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) let rec find_valid_buffer_aux_ps (t: base_typ) (addr: int) (ps: list b8) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) =
false
null
true
match ps with | [] -> () | a :: q -> find_valid_buffer_aux_ps t addr q h1 h2
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Prims.list", "Vale.X64.Memory.b8", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.find_valid_buffer_aux_ps", "Prims.unit", "Prims.l_and", "Prims.eq2", "Vale.Interop.Types.b8", "Prims.l_or", "Vale.Interop.Heap_s.list_disjoint_or_eq", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Vale.X64.Memory.sub_list", "Prims.squash", "FStar.Pervasives.Native.option", "Vale.X64.Memory.buffer", "Vale.X64.Memory.find_valid_buffer_aux", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val find_valid_buffer_aux_ps (t: base_typ) (addr: int) (ps: list b8) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2)
[ "recursion" ]
Vale.X64.Memory.find_valid_buffer_aux_ps
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> ps: Prims.list Vale.X64.Memory.b8 -> h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h1) == InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h2) /\ Vale.X64.Memory.sub_list ps (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h1))) (ensures Vale.X64.Memory.find_valid_buffer_aux t addr ps h1 == Vale.X64.Memory.find_valid_buffer_aux t addr ps h2)
{ "end_col": 51, "end_line": 381, "start_col": 2, "start_line": 379 }
FStar.Pervasives.Lemma
val loc_includes_refl (s:loc) : Lemma (loc_includes s s) [SMTPat (loc_includes s s)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_includes_refl s = M.loc_includes_refl s
val loc_includes_refl (s:loc) : Lemma (loc_includes s s) [SMTPat (loc_includes s s)] let loc_includes_refl s =
false
null
true
M.loc_includes_refl s
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "LowStar.Monotonic.Buffer.loc_includes_refl", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_includes_refl (s:loc) : Lemma (loc_includes s s) [SMTPat (loc_includes s s)]
[]
Vale.X64.Memory.loc_includes_refl
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (ensures Vale.X64.Memory.loc_includes s s) [SMTPat (Vale.X64.Memory.loc_includes s s)]
{ "end_col": 47, "end_line": 235, "start_col": 26, "start_line": 235 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
let valid_offset (t: base_typ) (n base: nat) (addr: int) (i: nat) =
false
null
false
exists j. {:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.nat", "Prims.int", "Prims.l_Exists", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.eq2", "Prims.op_Addition", "Vale.X64.Memory.scale_t", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_offset : t: Vale.Arch.HeapTypes_s.base_typ -> n: Prims.nat -> base: Prims.nat -> addr: Prims.int -> i: Prims.nat -> Prims.logical
[]
Vale.X64.Memory.valid_offset
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> n: Prims.nat -> base: Prims.nat -> addr: Prims.int -> i: Prims.nat -> Prims.logical
{ "end_col": 81, "end_line": 330, "start_col": 2, "start_line": 330 }
Prims.GTot
val valid_mem64 (ptr:int) (h:vale_heap) : GTot bool
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_mem64 ptr h = valid_mem (TUInt64) ptr h
val valid_mem64 (ptr:int) (h:vale_heap) : GTot bool let valid_mem64 ptr h =
false
null
false
valid_mem (TUInt64) ptr h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.valid_mem", "Vale.Arch.HeapTypes_s.TUInt64", "Prims.bool" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_mem64 (ptr:int) (h:vale_heap) : GTot bool
[]
Vale.X64.Memory.valid_mem64
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
{ "end_col": 49, "end_line": 360, "start_col": 24, "start_line": 360 }
Prims.GTot
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool let writeable_mem64 ptr h =
false
null
false
writeable_mem (TUInt64) ptr h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.writeable_mem", "Vale.Arch.HeapTypes_s.TUInt64", "Prims.bool" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool
[]
Vale.X64.Memory.writeable_mem64
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
{ "end_col": 57, "end_line": 410, "start_col": 28, "start_line": 410 }
FStar.Pervasives.Lemma
val same_underlying_seq (#t: base_typ) (h1 h2: vale_heap) (b: buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0
val same_underlying_seq (#t: base_typ) (h1 h2: vale_heap) (b: buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) let same_underlying_seq (#t: base_typ) (h1 h2: vale_heap) (b: buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) =
false
null
true
let db = get_downview b.bsrc in let rec aux (i: nat{i <= buffer_length b}) : Lemma (requires (forall (j: nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j: nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else (let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i + 1)) in aux 0
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.buffer", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.X64.Memory.buffer_length", "Prims.unit", "Prims.op_Subtraction", "Prims.l_and", "Prims.l_Forall", "Prims.op_LessThan", "Prims.eq2", "Vale.X64.Memory.base_typ_as_vale_type", "FStar.Seq.Base.index", "Vale.X64.Memory.buffer_as_seq", "FStar.Seq.Base.equal", "FStar.UInt8.t", "LowStar.BufferView.Down.as_seq", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims.bool", "Prims.op_Addition", "LowStar.BufferView.Up.as_seq_sel", "Vale.Interop.Types.base_typ_as_type", "LowStar.BufferView.Up.get_sel", "LowStar.BufferView.Up.buffer", "LowStar.BufferView.Up.mk_buffer", "Vale.X64.Memory.uint_view", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.__proj__Buffer__item__bsrc" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc)))
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val same_underlying_seq (#t: base_typ) (h1 h2: vale_heap) (b: buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b))
[]
Vale.X64.Memory.same_underlying_seq
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> b: Vale.X64.Memory.buffer t -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal (LowStar.BufferView.Down.as_seq (InteropHeap?.hs (Vale.Arch.HeapImpl._ih h1)) (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) (LowStar.BufferView.Down.as_seq (InteropHeap?.hs (Vale.Arch.HeapImpl._ih h2)) (Vale.Interop.Types.get_downview (Buffer?.bsrc b)))) (ensures FStar.Seq.Base.equal (Vale.X64.Memory.buffer_as_seq h1 b) (Vale.X64.Memory.buffer_as_seq h2 b))
{ "end_col": 10, "end_line": 222, "start_col": 3, "start_line": 206 }
Prims.GTot
val valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
val valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 let valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 =
false
null
false
let addr = (_ih h).addrs b in (forall (i: int). {:pattern (mt.[ i ])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[ i ] == tn)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.X64.Memory.b8", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.memtaint", "Vale.Arch.HeapTypes_s.taint", "Prims.l_Forall", "Prims.int", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.op_Addition", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Prims.eq2", "Vale.X64.Memory.op_String_Access", "Vale.Def.Words_s.nat64", "Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs", "Vale.Arch.HeapImpl._ih", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0
[]
Vale.X64.Memory.valid_taint_b8
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.b8 -> h: Vale.Arch.HeapImpl.vale_heap -> mt: Vale.X64.Memory.memtaint -> tn: Vale.Arch.HeapTypes_s.taint -> Prims.GTot Vale.Def.Prop_s.prop0
{ "end_col": 77, "end_line": 565, "start_col": 79, "start_line": 562 }
Prims.GTot
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 let valid_taint_buf #t b h mt tn =
false
null
false
valid_taint_b8 b h mt tn
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.memtaint", "Vale.Arch.HeapTypes_s.taint", "Vale.X64.Memory.valid_taint_b8", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn)
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0
[]
Vale.X64.Memory.valid_taint_buf
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t -> h: Vale.Arch.HeapImpl.vale_heap -> mt: Vale.X64.Memory.memtaint -> tn: Vale.Arch.HeapTypes_s.taint -> Prims.GTot Vale.Def.Prop_s.prop0
{ "end_col": 26, "end_line": 568, "start_col": 2, "start_line": 568 }
Prims.Tot
val default_of_typ (t: base_typ) : base_typ_as_vale_type t
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
val default_of_typ (t: base_typ) : base_typ_as_vale_type t let default_of_typ (t: base_typ) : base_typ_as_vale_type t =
false
null
false
allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.X64.Memory.base_typ_as_vale_type", "Prims.unit", "FStar.Pervasives.allow_inversion" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val default_of_typ (t: base_typ) : base_typ_as_vale_type t
[]
Vale.X64.Memory.default_of_typ
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> Vale.X64.Memory.base_typ_as_vale_type t
{ "end_col": 54, "end_line": 260, "start_col": 2, "start_line": 254 }
FStar.Pervasives.Lemma
val loc_includes_union_l (s1 s2 s:loc) : Lemma (requires (loc_includes s1 s \/ loc_includes s2 s)) (ensures (loc_includes (loc_union s1 s2) s))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s
val loc_includes_union_l (s1 s2 s:loc) : Lemma (requires (loc_includes s1 s \/ loc_includes s2 s)) (ensures (loc_includes (loc_union s1 s2) s)) let loc_includes_union_l s1 s2 s =
false
null
true
M.loc_includes_union_l s1 s2 s
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "LowStar.Monotonic.Buffer.loc_includes_union_l", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_includes_union_l (s1 s2 s:loc) : Lemma (requires (loc_includes s1 s \/ loc_includes s2 s)) (ensures (loc_includes (loc_union s1 s2) s))
[]
Vale.X64.Memory.loc_includes_union_l
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s1: Vale.X64.Memory.loc -> s2: Vale.X64.Memory.loc -> s: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.loc_includes s1 s \/ Vale.X64.Memory.loc_includes s2 s) (ensures Vale.X64.Memory.loc_includes (Vale.X64.Memory.loc_union s1 s2) s)
{ "end_col": 65, "end_line": 238, "start_col": 35, "start_line": 238 }
FStar.Pervasives.Lemma
val loc_includes_trans (s1 s2 s3:loc) : Lemma (requires (loc_includes s1 s2 /\ loc_includes s2 s3)) (ensures (loc_includes s1 s3))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3
val loc_includes_trans (s1 s2 s3:loc) : Lemma (requires (loc_includes s1 s2 /\ loc_includes s2 s3)) (ensures (loc_includes s1 s3)) let loc_includes_trans s1 s2 s3 =
false
null
true
M.loc_includes_trans s1 s2 s3
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "LowStar.Monotonic.Buffer.loc_includes_trans", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_includes_trans (s1 s2 s3:loc) : Lemma (requires (loc_includes s1 s2 /\ loc_includes s2 s3)) (ensures (loc_includes s1 s3))
[]
Vale.X64.Memory.loc_includes_trans
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s1: Vale.X64.Memory.loc -> s2: Vale.X64.Memory.loc -> s3: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.loc_includes s1 s2 /\ Vale.X64.Memory.loc_includes s2 s3) (ensures Vale.X64.Memory.loc_includes s1 s3)
{ "end_col": 63, "end_line": 236, "start_col": 34, "start_line": 236 }
FStar.Pervasives.Lemma
val modifies_goal_directed_refl (s:loc) (h:vale_heap) : Lemma (modifies_goal_directed s h h) [SMTPat (modifies_goal_directed s h h)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
val modifies_goal_directed_refl (s:loc) (h:vale_heap) : Lemma (modifies_goal_directed s h h) [SMTPat (modifies_goal_directed s h h)] let modifies_goal_directed_refl s h =
false
null
true
M.modifies_refl s (_ih h).hs
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "LowStar.Monotonic.Buffer.modifies_refl", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_goal_directed_refl (s:loc) (h:vale_heap) : Lemma (modifies_goal_directed s h h) [SMTPat (modifies_goal_directed s h h)]
[]
Vale.X64.Memory.modifies_goal_directed_refl
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> h: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (ensures Vale.X64.Memory.modifies_goal_directed s h h) [SMTPat (Vale.X64.Memory.modifies_goal_directed s h h)]
{ "end_col": 66, "end_line": 242, "start_col": 38, "start_line": 242 }
FStar.Pervasives.Lemma
val modifies_trans (s12:loc) (h1 h2:vale_heap) (s23:loc) (h3:vale_heap) : Lemma (requires (modifies s12 h1 h2 /\ modifies s23 h2 h3)) (ensures (modifies (loc_union s12 s23) h1 h3))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
val modifies_trans (s12:loc) (h1 h2:vale_heap) (s23:loc) (h3:vale_heap) : Lemma (requires (modifies s12 h1 h2 /\ modifies s23 h2 h3)) (ensures (modifies (loc_union s12 s23) h1 h3)) let modifies_trans s12 h1 h2 s23 h3 =
false
null
true
M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "LowStar.Monotonic.Buffer.modifies_trans", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_trans (s12:loc) (h1 h2:vale_heap) (s23:loc) (h3:vale_heap) : Lemma (requires (modifies s12 h1 h2 /\ modifies s23 h2 h3)) (ensures (modifies (loc_union s12 s23) h1 h3))
[]
Vale.X64.Memory.modifies_trans
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s12: Vale.X64.Memory.loc -> h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> s23: Vale.X64.Memory.loc -> h3: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies s12 h1 h2 /\ Vale.X64.Memory.modifies s23 h2 h3) (ensures Vale.X64.Memory.modifies (Vale.X64.Memory.loc_union s12 s23) h1 h3)
{ "end_col": 98, "end_line": 244, "start_col": 38, "start_line": 244 }
FStar.Pervasives.Lemma
val modifies_loc_includes (s1:loc) (h h':vale_heap) (s2:loc) : Lemma (requires (modifies s2 h h' /\ loc_includes s1 s2)) (ensures (modifies s1 h h'))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
val modifies_loc_includes (s1:loc) (h h':vale_heap) (s2:loc) : Lemma (requires (modifies s2 h h' /\ loc_includes s1 s2)) (ensures (modifies s1 h h')) let modifies_loc_includes s1 h h' s2 =
false
null
true
M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "LowStar.Monotonic.Buffer.modifies_loc_includes", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_loc_includes (s1:loc) (h h':vale_heap) (s2:loc) : Lemma (requires (modifies s2 h h' /\ loc_includes s1 s2)) (ensures (modifies s1 h h'))
[]
Vale.X64.Memory.modifies_loc_includes
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s1: Vale.X64.Memory.loc -> h: Vale.Arch.HeapImpl.vale_heap -> h': Vale.Arch.HeapImpl.vale_heap -> s2: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies s2 h h' /\ Vale.X64.Memory.loc_includes s1 s2) (ensures Vale.X64.Memory.modifies s1 h h')
{ "end_col": 91, "end_line": 243, "start_col": 39, "start_line": 243 }
FStar.Pervasives.Lemma
val loc_includes_union_r (s s1 s2:loc) : Lemma (requires (loc_includes s s1 /\ loc_includes s s2)) (ensures (loc_includes s (loc_union s1 s2))) [SMTPat (loc_includes s (loc_union s1 s2))]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2
val loc_includes_union_r (s s1 s2:loc) : Lemma (requires (loc_includes s s1 /\ loc_includes s s2)) (ensures (loc_includes s (loc_union s1 s2))) [SMTPat (loc_includes s (loc_union s1 s2))] let loc_includes_union_r s s1 s2 =
false
null
true
M.loc_includes_union_r s s1 s2
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "LowStar.Monotonic.Buffer.loc_includes_union_r", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_includes_union_r (s s1 s2:loc) : Lemma (requires (loc_includes s s1 /\ loc_includes s s2)) (ensures (loc_includes s (loc_union s1 s2))) [SMTPat (loc_includes s (loc_union s1 s2))]
[]
Vale.X64.Memory.loc_includes_union_r
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> s1: Vale.X64.Memory.loc -> s2: Vale.X64.Memory.loc -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.loc_includes s s1 /\ Vale.X64.Memory.loc_includes s s2) (ensures Vale.X64.Memory.loc_includes s (Vale.X64.Memory.loc_union s1 s2)) [SMTPat (Vale.X64.Memory.loc_includes s (Vale.X64.Memory.loc_union s1 s2))]
{ "end_col": 65, "end_line": 237, "start_col": 35, "start_line": 237 }
FStar.Pervasives.Lemma
val modifies_refl (s:loc) (h:vale_heap) : Lemma (modifies s h h) [SMTPat (modifies s h h)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_refl s h = M.modifies_refl s (_ih h).hs
val modifies_refl (s:loc) (h:vale_heap) : Lemma (modifies s h h) [SMTPat (modifies s h h)] let modifies_refl s h =
false
null
true
M.modifies_refl s (_ih h).hs
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "LowStar.Monotonic.Buffer.modifies_refl", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_refl (s:loc) (h:vale_heap) : Lemma (modifies s h h) [SMTPat (modifies s h h)]
[]
Vale.X64.Memory.modifies_refl
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Memory.loc -> h: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (ensures Vale.X64.Memory.modifies s h h) [SMTPat (Vale.X64.Memory.modifies s h h)]
{ "end_col": 52, "end_line": 241, "start_col": 24, "start_line": 241 }
FStar.Pervasives.Lemma
val modifies_goal_directed_trans (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma (requires modifies s12 h1 h2 /\ modifies_goal_directed s13 h2 h3 /\ loc_includes s13 s12 ) (ensures (modifies s13 h1 h3)) [SMTPat (modifies s12 h1 h2); SMTPat (modifies s13 h1 h3)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); ()
val modifies_goal_directed_trans (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma (requires modifies s12 h1 h2 /\ modifies_goal_directed s13 h2 h3 /\ loc_includes s13 s12 ) (ensures (modifies s13 h1 h3)) [SMTPat (modifies s12 h1 h2); SMTPat (modifies s13 h1 h3)] let modifies_goal_directed_trans s12 h1 h2 s13 h3 =
false
null
true
modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); ()
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "Prims.unit", "Vale.X64.Memory.modifies_loc_includes", "Vale.X64.Memory.loc_union", "Vale.X64.Memory.modifies_trans" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_goal_directed_trans (s12:loc) (h1 h2:vale_heap) (s13:loc) (h3:vale_heap) : Lemma (requires modifies s12 h1 h2 /\ modifies_goal_directed s13 h2 h3 /\ loc_includes s13 s12 ) (ensures (modifies s13 h1 h3)) [SMTPat (modifies s12 h1 h2); SMTPat (modifies s13 h1 h3)]
[]
Vale.X64.Memory.modifies_goal_directed_trans
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s12: Vale.X64.Memory.loc -> h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> s13: Vale.X64.Memory.loc -> h3: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies s12 h1 h2 /\ Vale.X64.Memory.modifies_goal_directed s13 h2 h3 /\ Vale.X64.Memory.loc_includes s13 s12) (ensures Vale.X64.Memory.modifies s13 h1 h3) [SMTPat (Vale.X64.Memory.modifies s12 h1 h2); SMTPat (Vale.X64.Memory.modifies s13 h1 h3)]
{ "end_col": 4, "end_line": 249, "start_col": 2, "start_line": 247 }
FStar.Pervasives.Lemma
val same_memTaint64 (b:buffer64) (mem0:vale_heap) (mem1:vale_heap) (memtaint0:memtaint) (memtaint1:memtaint) : Lemma (requires (modifies (loc_buffer b) mem0 mem1 /\ (forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p))) (ensures memtaint0 == memtaint1)
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
val same_memTaint64 (b:buffer64) (mem0:vale_heap) (mem1:vale_heap) (memtaint0:memtaint) (memtaint1:memtaint) : Lemma (requires (modifies (loc_buffer b) mem0 mem1 /\ (forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p))) (ensures memtaint0 == memtaint1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
false
null
true
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.buffer64", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.memtaint", "Vale.X64.Memory.same_memTaint", "Vale.Arch.HeapTypes_s.TUInt64", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1)
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val same_memTaint64 (b:buffer64) (mem0:vale_heap) (mem1:vale_heap) (memtaint0:memtaint) (memtaint1:memtaint) : Lemma (requires (modifies (loc_buffer b) mem0 mem1 /\ (forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p))) (ensures memtaint0 == memtaint1)
[]
Vale.X64.Memory.same_memTaint64
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer64 -> mem0: Vale.Arch.HeapImpl.vale_heap -> mem1: Vale.Arch.HeapImpl.vale_heap -> memtaint0: Vale.X64.Memory.memtaint -> memtaint1: Vale.X64.Memory.memtaint -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies (Vale.X64.Memory.loc_buffer b) mem0 mem1 /\ (forall (p: Prims.int). {:pattern FStar.Map.sel memtaint0 p\/FStar.Map.sel memtaint1 p} FStar.Map.sel memtaint0 p == FStar.Map.sel memtaint1 p)) (ensures memtaint0 == memtaint1)
{ "end_col": 57, "end_line": 607, "start_col": 2, "start_line": 607 }
FStar.Pervasives.Lemma
val same_memTaint128 (b:buffer128) (mem0:vale_heap) (mem1:vale_heap) (memtaint0:memtaint) (memtaint1:memtaint) : Lemma (requires (modifies (loc_buffer b) mem0 mem1 /\ (forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p))) (ensures memtaint0 == memtaint1)
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
val same_memTaint128 (b:buffer128) (mem0:vale_heap) (mem1:vale_heap) (memtaint0:memtaint) (memtaint1:memtaint) : Lemma (requires (modifies (loc_buffer b) mem0 mem1 /\ (forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p))) (ensures memtaint0 == memtaint1) let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
false
null
true
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.buffer128", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.memtaint", "Vale.X64.Memory.same_memTaint", "Vale.Arch.HeapTypes_s.TUInt128", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val same_memTaint128 (b:buffer128) (mem0:vale_heap) (mem1:vale_heap) (memtaint0:memtaint) (memtaint1:memtaint) : Lemma (requires (modifies (loc_buffer b) mem0 mem1 /\ (forall p.{:pattern Map.sel memtaint0 p \/ Map.sel memtaint1 p} Map.sel memtaint0 p == Map.sel memtaint1 p))) (ensures memtaint0 == memtaint1)
[]
Vale.X64.Memory.same_memTaint128
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer128 -> mem0: Vale.Arch.HeapImpl.vale_heap -> mem1: Vale.Arch.HeapImpl.vale_heap -> memtaint0: Vale.X64.Memory.memtaint -> memtaint1: Vale.X64.Memory.memtaint -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies (Vale.X64.Memory.loc_buffer b) mem0 mem1 /\ (forall (p: Prims.int). {:pattern FStar.Map.sel memtaint0 p\/FStar.Map.sel memtaint1 p} FStar.Map.sel memtaint0 p == FStar.Map.sel memtaint1 p)) (ensures memtaint0 == memtaint1)
{ "end_col": 58, "end_line": 610, "start_col": 2, "start_line": 610 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
let valid_taint_bufs (mem: vale_heap) (memTaint: memtaint) (ps: list b8) (ts: (b8 -> GTot taint)) =
false
null
false
forall b. {:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.memtaint", "Prims.list", "Vale.X64.Memory.b8", "Vale.Arch.HeapTypes_s.taint", "Prims.l_Forall", "Prims.l_imp", "FStar.List.Tot.Base.memP", "Vale.X64.Memory.valid_taint_b8", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = ()
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_taint_bufs : mem: Vale.Arch.HeapImpl.vale_heap -> memTaint: Vale.X64.Memory.memtaint -> ps: Prims.list Vale.X64.Memory.b8 -> ts: (_: Vale.X64.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint) -> Prims.logical
[]
Vale.X64.Memory.valid_taint_bufs
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mem: Vale.Arch.HeapImpl.vale_heap -> memTaint: Vale.X64.Memory.memtaint -> ps: Prims.list Vale.X64.Memory.b8 -> ts: (_: Vale.X64.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint) -> Prims.logical
{ "end_col": 92, "end_line": 635, "start_col": 2, "start_line": 635 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
let inv_heaplet_ids (hs: vale_heaplets) =
false
null
false
forall (i: heaplet_id). {:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapImpl.vale_heaplets", "Prims.l_Forall", "Vale.Arch.HeapImpl.heaplet_id", "Prims.eq2", "FStar.Pervasives.Native.option", "Vale.Arch.HeapImpl.__proj__ValeHeap__item__heapletId", "Vale.Lib.Map16.sel", "Vale.Arch.HeapImpl.vale_heap", "FStar.Pervasives.Native.Some", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inv_heaplet_ids : hs: Vale.Arch.HeapImpl.vale_heaplets -> Prims.logical
[]
Vale.X64.Memory.inv_heaplet_ids
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hs: Vale.Arch.HeapImpl.vale_heaplets -> Prims.logical
{ "end_col": 86, "end_line": 696, "start_col": 2, "start_line": 696 }
Prims.Ghost
val buffer_read (#t:base_typ) (b:buffer t) (i:int) (h:vale_heap) : Ghost (base_typ_as_vale_type t) (requires True) (ensures (fun v -> 0 <= i /\ i < buffer_length b /\ buffer_readable h b ==> v == Seq.index (buffer_as_seq h b) i ))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i
val buffer_read (#t:base_typ) (b:buffer t) (i:int) (h:vale_heap) : Ghost (base_typ_as_vale_type t) (requires True) (ensures (fun v -> 0 <= i /\ i < buffer_length b /\ buffer_readable h b ==> v == Seq.index (buffer_as_seq h b) i )) let buffer_read #t b i h =
false
null
false
if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Prims.op_BarBar", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "Vale.X64.Memory.buffer_length", "Vale.X64.Memory.default_of_typ", "Prims.bool", "FStar.Seq.Base.index", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.X64.Memory.buffer_as_seq" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val buffer_read (#t:base_typ) (b:buffer t) (i:int) (h:vale_heap) : Ghost (base_typ_as_vale_type t) (requires True) (ensures (fun v -> 0 <= i /\ i < buffer_length b /\ buffer_readable h b ==> v == Seq.index (buffer_as_seq h b) i ))
[]
Vale.X64.Memory.buffer_read
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t -> i: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost (Vale.X64.Memory.base_typ_as_vale_type t)
{ "end_col": 33, "end_line": 264, "start_col": 2, "start_line": 263 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) = let t = bi.bi_typ in let hid = bi.bi_heaplet in let hi = Map16.get hs hid in let b = bi.bi_buffer in let owns = owners hid in (bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\ buffer_as_seq hi b == buffer_as_seq h b /\ (valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\ (forall (i:int).{:pattern Set.mem i owns} buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\ True
let inv_buffer_info (bi: buffer_info) (owners: (heaplet_id -> Set.set int)) (h: vale_heap) (hs: vale_heaplets) (mt: memTaint_t) (modloc: loc) =
false
null
false
let t = bi.bi_typ in let hid = bi.bi_heaplet in let hi = Map16.get hs hid in let b = bi.bi_buffer in let owns = owners hid in (bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\ buffer_as_seq hi b == buffer_as_seq h b /\ (valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\ (forall (i: int). {:pattern Set.mem i owns} buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns ) /\ True
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapImpl.buffer_info", "Vale.Arch.HeapImpl.heaplet_id", "FStar.Set.set", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.Arch.HeapImpl.vale_heaplets", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.X64.Memory.loc", "Prims.l_and", "Prims.l_imp", "Prims.eq2", "Vale.Arch.HeapImpl.mutability", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_mutable", "Vale.Arch.HeapImpl.Mutable", "Vale.X64.Memory.loc_includes", "Vale.X64.Memory.loc_buffer", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ", "Vale.X64.Memory.buffer_readable", "FStar.Seq.Base.seq", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.X64.Memory.buffer_as_seq", "Prims.l_iff", "Vale.X64.Memory.valid_taint_buf", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_taint", "Prims.l_Forall", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.X64.Memory.buffer_addr", "Prims.op_LessThan", "Prims.op_Addition", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "FStar.Set.mem", "Prims.l_True", "Vale.Arch.HeapImpl.buffer", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer", "Vale.Lib.Map16.get", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet", "Vale.Arch.HeapTypes_s.base_typ", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i let inv_heaplet (owns:Set.set int) (h hi:vale_heap) = h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True ) /\ True
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inv_buffer_info : bi: Vale.Arch.HeapImpl.buffer_info -> owners: (_: Vale.Arch.HeapImpl.heaplet_id -> FStar.Set.set Prims.int) -> h: Vale.Arch.HeapImpl.vale_heap -> hs: Vale.Arch.HeapImpl.vale_heaplets -> mt: Vale.Arch.HeapTypes_s.memTaint_t -> modloc: Vale.X64.Memory.loc -> Prims.logical
[]
Vale.X64.Memory.inv_buffer_info
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
bi: Vale.Arch.HeapImpl.buffer_info -> owners: (_: Vale.Arch.HeapImpl.heaplet_id -> FStar.Set.set Prims.int) -> h: Vale.Arch.HeapImpl.vale_heap -> hs: Vale.Arch.HeapImpl.vale_heaplets -> mt: Vale.Arch.HeapTypes_s.memTaint_t -> modloc: Vale.X64.Memory.loc -> Prims.logical
{ "end_col": 6, "end_line": 722, "start_col": 135, "start_line": 710 }
FStar.Pervasives.Lemma
val seq_upd (#b: _) (h: HS.mem) (vb: UV.buffer b {UV.live h vb}) (i: nat{i < UV.length vb}) (x: b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0
val seq_upd (#b: _) (h: HS.mem) (vb: UV.buffer b {UV.live h vb}) (i: nat{i < UV.length vb}) (x: b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) let seq_upd (#b: _) (h: HS.mem) (vb: UV.buffer b {UV.live h vb}) (i: nat{i < UV.length vb}) (x: b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) =
false
null
true
let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k: nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j: nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j: nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else (UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k + 1)) in aux 0
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "LowStar.BufferView.Up.buffer", "LowStar.BufferView.Up.live", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowStar.BufferView.Up.length", "Prims.unit", "Prims.op_Subtraction", "FStar.Seq.Base.length", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.l_Forall", "Prims.l_imp", "Prims.eq2", "FStar.Seq.Base.index", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_Equality", "Prims.bool", "Prims.op_Addition", "LowStar.BufferView.Up.as_seq_sel", "LowStar.BufferView.Up.upd", "LowStar.BufferView.Up.sel_upd", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "FStar.Seq.Properties.lseq", "LowStar.BufferView.Up.as_seq", "Prims.l_True", "FStar.Seq.Base.equal" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val seq_upd (#b: _) (h: HS.mem) (vb: UV.buffer b {UV.live h vb}) (i: nat{i < UV.length vb}) (x: b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb))
[]
Vale.X64.Memory.seq_upd
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: FStar.Monotonic.HyperStack.mem -> vb: LowStar.BufferView.Up.buffer b {LowStar.BufferView.Up.live h vb} -> i: Prims.nat{i < LowStar.BufferView.Up.length vb} -> x: b -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (FStar.Seq.Base.upd (LowStar.BufferView.Up.as_seq h vb) i x) (LowStar.BufferView.Up.as_seq (LowStar.BufferView.Up.upd h vb i x) vb))
{ "end_col": 10, "end_line": 291, "start_col": 3, "start_line": 276 }
Prims.Tot
val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let is_initial_heap layout h = h == layout.vl_inner.vl_old_heap /\ not layout.vl_inner.vl_heaplets_initialized
val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0 let is_initial_heap layout h =
false
null
false
h == layout.vl_inner.vl_old_heap /\ not layout.vl_inner.vl_heaplets_initialized
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapImpl.vale_heap_layout", "Vale.Arch.HeapImpl.vale_heap", "Prims.l_and", "Prims.eq2", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner", "Prims.b2t", "Prims.op_Negation", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i let inv_heaplet (owns:Set.set int) (h hi:vale_heap) = h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True ) /\ True // heaplet state matches heap state let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) = let t = bi.bi_typ in let hid = bi.bi_heaplet in let hi = Map16.get hs hid in let b = bi.bi_buffer in let owns = owners hid in (bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\ buffer_as_seq hi b == buffer_as_seq h b /\ (valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\ (forall (i:int).{:pattern Set.mem i owns} buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\ True let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) = let bs = layout.vl_buffers in modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap (forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)} layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i) ) /\ (forall (i:heaplet_id).{:pattern (Map16.sel hs i)} inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\ (forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==> inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\ (forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)} i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\ True
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0
[]
Vale.X64.Memory.is_initial_heap
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
layout: Vale.Arch.HeapImpl.vale_heap_layout -> h: Vale.Arch.HeapImpl.vale_heap -> Vale.Def.Prop_s.prop0
{ "end_col": 45, "end_line": 740, "start_col": 2, "start_line": 739 }
Prims.GTot
val valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h
val valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool let valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool =
false
null
false
DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.X64.Memory.b8", "Vale.Arch.HeapImpl.vale_heap", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.op_Modulus", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.Interop.Types.view_n", "Vale.X64.Memory.addr_in_ptr", "Prims.bool" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool
[]
Vale.X64.Memory.valid_buffer
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> b: Vale.X64.Memory.b8 -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
{ "end_col": 25, "end_line": 342, "start_col": 2, "start_line": 341 }
Prims.Ghost
val buffer_write (#t:base_typ) (b:buffer t) (i:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires buffer_readable h b /\ buffer_writeable b) (ensures (fun h' -> 0 <= i /\ i < buffer_length b /\ buffer_readable h b ==> modifies (loc_buffer b) h h' /\ get_heaplet_id h' == get_heaplet_id h /\ buffer_readable h' b /\ buffer_as_seq h' b == Seq.upd (buffer_as_seq h b) i v ))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end
val buffer_write (#t:base_typ) (b:buffer t) (i:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires buffer_readable h b /\ buffer_writeable b) (ensures (fun h' -> 0 <= i /\ i < buffer_length b /\ buffer_readable h b ==> modifies (loc_buffer b) h h' /\ get_heaplet_id h' == get_heaplet_id h /\ buffer_readable h' b /\ buffer_as_seq h' b == Seq.upd (buffer_as_seq h b) i v )) let buffer_write #t b i v h =
false
null
false
if i < 0 || i >= buffer_length b then h else let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h'
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Prims.int", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.Arch.HeapImpl.vale_heap", "Prims.op_BarBar", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "Vale.X64.Memory.buffer_length", "Prims.bool", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "Vale.X64.Memory.buffer_as_seq", "FStar.Seq.Base.upd", "Vale.X64.Memory.seq_upd", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Heap_s.__proj__InteropHeap__item__hs", "Vale.Arch.HeapImpl._ih", "Vale.X64.Memory.v_of_typ", "Vale.Arch.HeapImpl.ValeHeap", "FStar.Ghost.hide", "Vale.Interop.Heap_s.interop_heap", "Vale.Arch.HeapImpl.__proj__ValeHeap__item__heapletId", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Interop.Heap_s.correct_down", "Vale.Interop.down_mem", "Vale.Interop.Heap_s.InteropHeap", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs", "FStar.Monotonic.HyperStack.mem", "LowStar.BufferView.Up.upd", "LowStar.BufferView.Up.upd_equal_domains", "LowStar.BufferView.Up.upd_modifies", "LowStar.BufferView.Up.buffer", "LowStar.BufferView.Up.mk_buffer", "FStar.UInt8.t", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "LowStar.BufferView.Up.view", "Prims.eq2", "Prims.pos", "LowStar.BufferView.Up.__proj__View__item__n", "Vale.Interop.Types.view_n", "Vale.X64.Memory.uint_view" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val buffer_write (#t:base_typ) (b:buffer t) (i:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires buffer_readable h b /\ buffer_writeable b) (ensures (fun h' -> 0 <= i /\ i < buffer_length b /\ buffer_readable h b ==> modifies (loc_buffer b) h h' /\ get_heaplet_id h' == get_heaplet_id h /\ buffer_readable h' b /\ buffer_as_seq h' b == Seq.upd (buffer_as_seq h b) i v ))
[]
Vale.X64.Memory.buffer_write
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t -> i: Prims.int -> v: Vale.X64.Memory.base_typ_as_vale_type t -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost Vale.Arch.HeapImpl.vale_heap
{ "end_col": 5, "end_line": 308, "start_col": 2, "start_line": 294 }
Prims.Ghost
val get_addr_in_ptr (t: base_typ) (n base addr i: nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i])
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1)
val get_addr_in_ptr (t: base_typ) (n base addr i: nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) let rec get_addr_in_ptr (t: base_typ) (n base addr i: nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) =
false
null
false
if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "Vale.X64.Memory.scale_t", "Prims.bool", "Vale.X64.Memory.get_addr_in_ptr", "Vale.X64.Memory.valid_offset", "Prims.eq2" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i])
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_addr_in_ptr (t: base_typ) (n base addr i: nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i])
[ "recursion" ]
Vale.X64.Memory.get_addr_in_ptr
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> n: Prims.nat -> base: Prims.nat -> addr: Prims.nat -> i: Prims.nat -> Prims.Ghost Prims.nat
{ "end_col": 44, "end_line": 338, "start_col": 2, "start_line": 337 }
Prims.GTot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h
let valid_mem (t: base_typ) addr (h: vale_heap) =
false
null
false
valid_mem_aux t addr (_ih h).ptrs h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.valid_mem_aux", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.bool" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_mem : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
[]
Vale.X64.Memory.valid_mem
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
{ "end_col": 83, "end_line": 359, "start_col": 48, "start_line": 359 }
Prims.Tot
val mem_inv (h:vale_full_heap) : prop0
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let mem_inv h = h.vf_heap.heapletId == None /\ inv_heaplet_ids h.vf_heaplets /\ (if h.vf_layout.vl_inner.vl_heaplets_initialized then inv_heaplets h.vf_layout.vl_inner h.vf_heap h.vf_heaplets h.vf_layout.vl_taint else h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap )
val mem_inv (h:vale_full_heap) : prop0 let mem_inv h =
false
null
false
h.vf_heap.heapletId == None /\ inv_heaplet_ids h.vf_heaplets /\ (if h.vf_layout.vl_inner.vl_heaplets_initialized then inv_heaplets h.vf_layout.vl_inner h.vf_heap h.vf_heaplets h.vf_layout.vl_taint else h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapImpl.vale_full_heap", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "Vale.Arch.HeapImpl.heaplet_id", "Vale.Arch.HeapImpl.__proj__ValeHeap__item__heapletId", "Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap", "FStar.Pervasives.Native.None", "Vale.X64.Memory.inv_heaplet_ids", "Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner", "Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout", "Vale.X64.Memory.inv_heaplets", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint", "Prims.bool", "Vale.Arch.HeapImpl.vale_heaplets", "Vale.Arch.HeapImpl.empty_vale_heaplets", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap", "Prims.logical", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i let inv_heaplet (owns:Set.set int) (h hi:vale_heap) = h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True ) /\ True // heaplet state matches heap state let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) = let t = bi.bi_typ in let hid = bi.bi_heaplet in let hi = Map16.get hs hid in let b = bi.bi_buffer in let owns = owners hid in (bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\ buffer_as_seq hi b == buffer_as_seq h b /\ (valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\ (forall (i:int).{:pattern Set.mem i owns} buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\ True let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) = let bs = layout.vl_buffers in modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap (forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)} layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i) ) /\ (forall (i:heaplet_id).{:pattern (Map16.sel hs i)} inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\ (forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==> inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\ (forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)} i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\ True let is_initial_heap layout h = h == layout.vl_inner.vl_old_heap /\ not layout.vl_inner.vl_heaplets_initialized
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mem_inv (h:vale_full_heap) : prop0
[]
Vale.X64.Memory.mem_inv
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Arch.HeapImpl.vale_full_heap -> Vale.Def.Prop_s.prop0
{ "end_col": 3, "end_line": 751, "start_col": 2, "start_line": 743 }
Prims.Tot
val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let layout_buffers layout = layout.vl_buffers
val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info let layout_buffers layout =
false
null
false
layout.vl_buffers
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapImpl.vale_heap_layout_inner", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers", "FStar.Seq.Base.seq", "Vale.Arch.HeapImpl.buffer_info" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i let inv_heaplet (owns:Set.set int) (h hi:vale_heap) = h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True ) /\ True // heaplet state matches heap state let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) = let t = bi.bi_typ in let hid = bi.bi_heaplet in let hi = Map16.get hs hid in let b = bi.bi_buffer in let owns = owners hid in (bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\ buffer_as_seq hi b == buffer_as_seq h b /\ (valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\ (forall (i:int).{:pattern Set.mem i owns} buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\ True let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) = let bs = layout.vl_buffers in modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap (forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)} layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i) ) /\ (forall (i:heaplet_id).{:pattern (Map16.sel hs i)} inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\ (forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==> inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\ (forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)} i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\ True let is_initial_heap layout h = h == layout.vl_inner.vl_old_heap /\ not layout.vl_inner.vl_heaplets_initialized let mem_inv h = h.vf_heap.heapletId == None /\ inv_heaplet_ids h.vf_heaplets /\ (if h.vf_layout.vl_inner.vl_heaplets_initialized then inv_heaplets h.vf_layout.vl_inner h.vf_heap h.vf_heaplets h.vf_layout.vl_taint else h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap ) let layout_heaplets_initialized layout = layout.vl_heaplets_initialized let layout_old_heap layout = layout.vl_old_heap
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info
[]
Vale.X64.Memory.layout_buffers
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info
{ "end_col": 45, "end_line": 756, "start_col": 28, "start_line": 756 }
Prims.GTot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h
let find_valid_buffer (t: base_typ) (addr: int) (h: vale_heap) =
false
null
false
find_valid_buffer_aux t addr (_ih h).ptrs h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.find_valid_buffer_aux", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "FStar.Pervasives.Native.option", "Vale.X64.Memory.buffer" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val find_valid_buffer : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot (FStar.Pervasives.Native.option (Vale.X64.Memory.buffer t))
[]
Vale.X64.Memory.find_valid_buffer
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot (FStar.Pervasives.Native.option (Vale.X64.Memory.buffer t))
{ "end_col": 105, "end_line": 373, "start_col": 62, "start_line": 373 }
FStar.Pervasives.Lemma
val find_valid_buffer_ps (t: base_typ) (addr: int) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
val find_valid_buffer_ps (t: base_typ) (addr: int) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) let find_valid_buffer_ps (t: base_typ) (addr: int) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) =
false
null
true
find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.find_valid_buffer_aux_ps", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.unit", "Prims.eq2", "Prims.list", "Vale.Interop.Types.b8", "Prims.l_or", "Vale.Interop.Heap_s.list_disjoint_or_eq", "Prims.squash", "FStar.Pervasives.Native.option", "Vale.X64.Memory.buffer", "Vale.X64.Memory.find_valid_buffer", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val find_valid_buffer_ps (t: base_typ) (addr: int) (h1 h2: vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2)
[]
Vale.X64.Memory.find_valid_buffer_ps
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h1) == InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h2)) (ensures Vale.X64.Memory.find_valid_buffer t addr h1 == Vale.X64.Memory.find_valid_buffer t addr h2)
{ "end_col": 53, "end_line": 387, "start_col": 2, "start_line": 387 }
Prims.GTot
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool let writeable_mem128 ptr h =
false
null
false
writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.writeable_mem_aux", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.bool" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = ()
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool
[]
Vale.X64.Memory.writeable_mem128
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool
{ "end_col": 76, "end_line": 492, "start_col": 29, "start_line": 492 }
Prims.Ghost
val valid_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h
val valid_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) let rec valid_mem_aux (t: base_typ) addr (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) =
false
null
false
match ps with | [] -> false | a :: q -> valid_buffer t addr a h || valid_mem_aux t addr q h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Prims.list", "Vale.X64.Memory.b8", "Vale.Arch.HeapImpl.vale_heap", "Prims.op_BarBar", "Vale.X64.Memory.valid_buffer", "Vale.X64.Memory.valid_mem_aux", "Prims.bool", "Vale.X64.Memory.sub_list", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.l_iff", "Prims.b2t", "Prims.l_Exists", "Vale.X64.Memory.buffer", "Prims.l_and", "FStar.List.Tot.Base.memP" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h))
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_mem_aux (t: base_typ) (addr: _) (ps: list b8) (h: vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x: buffer t). {:pattern (List.memP x ps)\/(valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h))
[ "recursion" ]
Vale.X64.Memory.valid_mem_aux
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> ps: Prims.list Vale.X64.Memory.b8 -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost Prims.bool
{ "end_col": 63, "end_line": 358, "start_col": 2, "start_line": 356 }
Prims.GTot
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h
let find_writeable_buffer (t: base_typ) (addr: int) (h: vale_heap) =
false
null
false
find_writeable_buffer_aux t addr (_ih h).ptrs h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "sometrivial" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.find_writeable_buffer_aux", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "FStar.Pervasives.Native.option", "Vale.X64.Memory.buffer" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val find_writeable_buffer : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot (FStar.Pervasives.Native.option (Vale.X64.Memory.buffer t))
[]
Vale.X64.Memory.find_writeable_buffer
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot (FStar.Pervasives.Native.option (Vale.X64.Memory.buffer t))
{ "end_col": 49, "end_line": 425, "start_col": 2, "start_line": 425 }
FStar.Pervasives.Lemma
val length_t_eq (t: base_typ) (b: buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
val length_t_eq (t: base_typ) (b: buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) let length_t_eq (t: base_typ) (b: buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) =
false
null
true
let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "FStar.Math.Lib.lemma_div_def", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.view_n", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Vale.X64.Memory.buffer_length", "Prims.op_Division", "LowStar.BufferView.Up.length_eq", "Vale.Interop.Types.base_typ_as_type", "LowStar.BufferView.Up.buffer", "LowStar.BufferView.Up.mk_buffer", "Vale.X64.Memory.uint_view", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Prims.l_True", "Prims.squash", "FStar.Mul.op_Star", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val length_t_eq (t: base_typ) (b: buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t))
[]
Vale.X64.Memory.length_t_eq
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> b: Vale.X64.Memory.buffer t -> FStar.Pervasives.Lemma (ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) == Vale.X64.Memory.buffer_length b * Vale.Interop.Types.view_n t)
{ "end_col": 56, "end_line": 444, "start_col": 75, "start_line": 439 }
Prims.Ghost
val find_valid_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps)
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
val find_valid_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) let rec find_valid_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) =
false
null
false
match ps with | [] -> None | a :: q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Prims.list", "Vale.X64.Memory.b8", "Vale.Arch.HeapImpl.vale_heap", "FStar.Pervasives.Native.None", "Vale.X64.Memory.buffer", "Vale.X64.Memory.valid_buffer", "FStar.Pervasives.Native.Some", "Prims.bool", "Vale.X64.Memory.find_valid_buffer_aux", "FStar.Pervasives.Native.option", "Vale.X64.Memory.sub_list", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.b2t", "Prims.op_Negation", "Vale.X64.Memory.valid_mem_aux", "Prims.l_and", "FStar.List.Tot.Base.memP" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val find_valid_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps)
[ "recursion" ]
Vale.X64.Memory.find_valid_buffer_aux
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> ps: Prims.list Vale.X64.Memory.b8 -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost (FStar.Pervasives.Native.option (Vale.X64.Memory.buffer t))
{ "end_col": 88, "end_line": 371, "start_col": 2, "start_line": 369 }
Prims.Ghost
val find_writeable_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> (match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps))
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
val find_writeable_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> (match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps)) let rec find_writeable_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> (match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps)) =
false
null
false
match ps with | [] -> None | a :: q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.int", "Prims.list", "Vale.X64.Memory.b8", "Vale.Arch.HeapImpl.vale_heap", "FStar.Pervasives.Native.None", "Vale.X64.Memory.buffer", "Vale.X64.Memory.writeable_buffer", "FStar.Pervasives.Native.Some", "Prims.bool", "Vale.X64.Memory.find_writeable_buffer_aux", "FStar.Pervasives.Native.option", "Vale.X64.Memory.sub_list", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "Vale.Arch.HeapImpl._ih", "Prims.b2t", "Prims.op_Negation", "Vale.X64.Memory.writeable_mem_aux", "Prims.l_and", "FStar.List.Tot.Base.memP" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps ))
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val find_writeable_buffer_aux (t: base_typ) (addr: int) (ps: list b8) (h: vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> (match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps))
[ "recursion" ]
Vale.X64.Memory.find_writeable_buffer_aux
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> ps: Prims.list Vale.X64.Memory.b8 -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.Ghost (FStar.Pervasives.Native.option (Vale.X64.Memory.buffer t))
{ "end_col": 96, "end_line": 422, "start_col": 2, "start_line": 420 }
FStar.Pervasives.Lemma
val lemma_store_mem64 (b:buffer64) (i:nat) (v:nat64) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem64 (buffer_addr b h + scale8 i) v h == buffer_write b i v h )
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h
val lemma_store_mem64 (b:buffer64) (i:nat) (v:nat64) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem64 (buffer_addr b h + scale8 i) v h == buffer_write b i v h ) let lemma_store_mem64 b i v h =
false
null
true
lemma_store_mem TUInt64 b i v h
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.X64.Memory.buffer64", "Prims.nat", "Vale.Def.Types_s.nat64", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.lemma_store_mem", "Vale.Arch.HeapTypes_s.TUInt64", "Prims.unit" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b)
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_store_mem64 (b:buffer64) (i:nat) (v:nat64) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem64 (buffer_addr b h + scale8 i) v h == buffer_write b i v h )
[]
Vale.X64.Memory.lemma_store_mem64
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer64 -> i: Prims.nat -> v: Vale.Def.Types_s.nat64 -> h: Vale.Arch.HeapImpl.vale_heap -> FStar.Pervasives.Lemma (requires i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\ Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.buffer_writeable b) (ensures Vale.X64.Memory.store_mem64 (Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale8 i) v h == Vale.X64.Memory.buffer_write b i v h)
{ "end_col": 63, "end_line": 540, "start_col": 32, "start_line": 540 }
FStar.Pervasives.Lemma
val same_memTaint (t: base_typ) (b: buffer t) (mem0 mem1: vale_heap) (memT0 memT1: memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1)
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1)
val same_memTaint (t: base_typ) (b: buffer t) (mem0 mem1: vale_heap) (memT0 memT1: memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) let same_memTaint (t: base_typ) (b: buffer t) (mem0 mem1: vale_heap) (memT0 memT1: memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) =
false
null
true
assert (Map.equal memT0 memT1)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.memtaint", "Prims._assert", "FStar.Map.equal", "Prims.int", "Vale.Arch.HeapTypes_s.taint", "Prims.unit", "Prims.l_and", "Vale.X64.Memory.modifies", "Vale.X64.Memory.loc_buffer", "Prims.l_Forall", "Prims.eq2", "FStar.Map.sel", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p))
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val same_memTaint (t: base_typ) (b: buffer t) (mem0 mem1: vale_heap) (memT0 memT1: memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1)
[]
Vale.X64.Memory.same_memTaint
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> b: Vale.X64.Memory.buffer t -> mem0: Vale.Arch.HeapImpl.vale_heap -> mem1: Vale.Arch.HeapImpl.vale_heap -> memT0: Vale.X64.Memory.memtaint -> memT1: Vale.X64.Memory.memtaint -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies (Vale.X64.Memory.loc_buffer b) mem0 mem1 /\ (forall (p: Prims.int). FStar.Map.sel memT0 p == FStar.Map.sel memT1 p)) (ensures memT0 == memT1)
{ "end_col": 32, "end_line": 604, "start_col": 2, "start_line": 604 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let inv_heaplet (owns:Set.set int) (h hi:vale_heap) = h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True ) /\ True
let inv_heaplet (owns: Set.set int) (h hi: vale_heap) =
false
null
false
h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i: int). {:pattern Set.mem i owns\/Set.mem i (Map.domain h.mh)\/Map.sel h.mh i\/Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True) /\ True
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "FStar.Set.set", "Prims.int", "Vale.Arch.HeapImpl.vale_heap", "Prims.l_and", "Prims.eq2", "Prims.list", "Vale.Interop.Types.b8", "Prims.l_or", "Vale.Interop.Heap_s.list_disjoint_or_eq", "Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs", "FStar.Ghost.reveal", "Vale.Interop.Heap_s.interop_heap", "Vale.Arch.HeapImpl.__proj__ValeHeap__item__ih", "FStar.Map.domain", "Vale.Def.Types_s.nat8", "Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "FStar.Set.mem", "FStar.Map.sel", "Prims.l_True", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inv_heaplet : owns: FStar.Set.set Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> hi: Vale.Arch.HeapImpl.vale_heap -> Prims.logical
[]
Vale.X64.Memory.inv_heaplet
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
owns: FStar.Set.set Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> hi: Vale.Arch.HeapImpl.vale_heap -> Prims.logical
{ "end_col": 6, "end_line": 707, "start_col": 2, "start_line": 699 }
FStar.Pervasives.Lemma
val modifies_valid_taint (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) (mt:memtaint) (tn:taint) : Lemma (requires modifies p h h') (ensures valid_taint_buf b h mt tn <==> valid_taint_buf b h' mt tn) [SMTPat (modifies p h h'); SMTPat (valid_taint_buf b h' mt tn)]
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right())
val modifies_valid_taint (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) (mt:memtaint) (tn:taint) : Lemma (requires modifies p h h') (ensures valid_taint_buf b h mt tn <==> valid_taint_buf b h' mt tn) [SMTPat (modifies p h h'); SMTPat (valid_taint_buf b h' mt tn)] let modifies_valid_taint #t b p h h' mt tn =
false
null
true
let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i: nat{i < DV.length dv}) : Lemma (mt.[ (_ih h').addrs b + i ] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i: nat{i < DV.length dv}) : Lemma (mt.[ (_ih h).addrs b + i ] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left ()); (Classical.move_requires imp_right ())
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Vale.X64.Memory.loc", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.memtaint", "Vale.Arch.HeapTypes_s.taint", "FStar.Classical.move_requires", "Prims.unit", "Vale.X64.Memory.valid_taint_buf", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Prims.op_Equality", "Vale.X64.Memory.op_String_Access", "Prims.int", "Prims.op_Addition", "Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs", "Vale.Arch.HeapImpl._ih", "Prims.l_True", "FStar.Map.sel", "Vale.X64.Memory.apply_taint_buf", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1
false
false
Vale.X64.Memory.fst
{ "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_valid_taint (#t:base_typ) (b:buffer t) (p:loc) (h h':vale_heap) (mt:memtaint) (tn:taint) : Lemma (requires modifies p h h') (ensures valid_taint_buf b h mt tn <==> valid_taint_buf b h' mt tn) [SMTPat (modifies p h h'); SMTPat (valid_taint_buf b h' mt tn)]
[]
Vale.X64.Memory.modifies_valid_taint
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.Memory.buffer t -> p: Vale.X64.Memory.loc -> h: Vale.Arch.HeapImpl.vale_heap -> h': Vale.Arch.HeapImpl.vale_heap -> mt: Vale.X64.Memory.memtaint -> tn: Vale.Arch.HeapTypes_s.taint -> FStar.Pervasives.Lemma (requires Vale.X64.Memory.modifies p h h') (ensures Vale.X64.Memory.valid_taint_buf b h mt tn <==> Vale.X64.Memory.valid_taint_buf b h' mt tn) [ SMTPat (Vale.X64.Memory.modifies p h h'); SMTPat (Vale.X64.Memory.valid_taint_buf b h' mt tn) ]
{ "end_col": 39, "end_line": 628, "start_col": 44, "start_line": 612 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet)
let valid_layout_data_buffer (t: base_typ) (b: buffer t) (layout: vale_heap_layout_inner) (hid: heaplet_id) (write: bool) =
false
null
false
exists (n: nat). {:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ (let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet)
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.X64.Memory.buffer", "Vale.Arch.HeapImpl.vale_heap_layout_inner", "Vale.Arch.HeapImpl.heaplet_id", "Prims.bool", "Prims.l_Exists", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Arch.HeapImpl.buffer_info", "Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers", "Prims.eq2", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ", "Vale.Interop.Types.b8", "Prims.l_or", "Prims.int", "Prims.op_Modulus", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Vale.Interop.Types.view_n", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer", "Prims.l_imp", "Vale.Arch.HeapImpl.mutability", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_mutable", "Vale.Arch.HeapImpl.Mutable", "Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet", "FStar.Seq.Base.index", "Prims.logical" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b)
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_layout_data_buffer : t: Vale.Arch.HeapTypes_s.base_typ -> b: Vale.X64.Memory.buffer t -> layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> hid: Vale.Arch.HeapImpl.heaplet_id -> write: Prims.bool -> Prims.logical
[]
Vale.X64.Memory.valid_layout_data_buffer
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Vale.Arch.HeapTypes_s.base_typ -> b: Vale.X64.Memory.buffer t -> layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> hid: Vale.Arch.HeapImpl.heaplet_id -> write: Prims.bool -> Prims.logical
{ "end_col": 25, "end_line": 685, "start_col": 2, "start_line": 680 }
FStar.Pervasives.Lemma
val write_taint_lemma (i: nat) (mem: IB.interop_heap) (ts: (b8 -> GTot taint)) (b: b8) (accu: memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j: int). {:pattern accu.[ j ]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[ j ] = ts b)) (ensures (let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j. {:pattern m.[ j ]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[ j ] = ts b) /\ (forall j. {:pattern m.[ j ]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[ j ] == accu.[ j ]))) (decreases %[DV.length (get_downview b.bsrc) - i])
[ { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_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": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Types", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu
val write_taint_lemma (i: nat) (mem: IB.interop_heap) (ts: (b8 -> GTot taint)) (b: b8) (accu: memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j: int). {:pattern accu.[ j ]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[ j ] = ts b)) (ensures (let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j. {:pattern m.[ j ]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[ j ] = ts b) /\ (forall j. {:pattern m.[ j ]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[ j ] == accu.[ j ]))) (decreases %[DV.length (get_downview b.bsrc) - i]) let rec write_taint_lemma (i: nat) (mem: IB.interop_heap) (ts: (b8 -> GTot taint)) (b: b8) (accu: memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j: int). {:pattern accu.[ j ]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[ j ] = ts b)) (ensures (let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j. {:pattern m.[ j ]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[ j ] = ts b) /\ (forall j. {:pattern m.[ j ]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[ j ] == accu.[ j ]))) (decreases %[DV.length (get_downview b.bsrc) - i]) =
false
null
true
let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[ addr + i ] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j. {:pattern m.[ j ]} addr <= j /\ j < addr + i + 1 ==> new_accu.[ j ] == ts b); write_taint_lemma (i + 1) mem ts b new_accu
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "lemma", "" ]
[ "Prims.nat", "Vale.Interop.Heap_s.interop_heap", "Vale.X64.Memory.b8", "Vale.Arch.HeapTypes_s.taint", "Vale.X64.Memory.memtaint", "Prims.op_GreaterThanOrEqual", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.__proj__Buffer__item__src", "Vale.Interop.Types.b8_preorder", "Vale.Interop.Types.__proj__Buffer__item__writeable", "Vale.Interop.Types.base_typ_as_type", "Vale.Interop.Types.__proj__Buffer__item__bsrc", "Prims.bool", "Vale.X64.Memory.write_taint_lemma", "Prims.op_Addition", "Prims.unit", "Prims._assert", "Prims.l_Forall", "Prims.int", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.eq2", "Vale.X64.Memory.op_String_Access", "FStar.Set.equal", "FStar.Map.domain", "FStar.Set.complement", "FStar.Set.empty", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.Interop.Base.write_taint", "FStar.Map.t", "Vale.X64.Memory.op_String_Assignment", "Vale.Def.Words_s.nat64", "Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs", "Prims.op_Equality", "Prims.squash", "Prims.l_or", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j])))
false
false
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val write_taint_lemma (i: nat) (mem: IB.interop_heap) (ts: (b8 -> GTot taint)) (b: b8) (accu: memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j: int). {:pattern accu.[ j ]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[ j ] = ts b)) (ensures (let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j. {:pattern m.[ j ]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[ j ] = ts b) /\ (forall j. {:pattern m.[ j ]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[ j ] == accu.[ j ]))) (decreases %[DV.length (get_downview b.bsrc) - i])
[ "recursion" ]
Vale.X64.Memory.write_taint_lemma
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
i: Prims.nat -> mem: Vale.Interop.Heap_s.interop_heap -> ts: (_: Vale.X64.Memory.b8 -> Prims.GTot Vale.Arch.HeapTypes_s.taint) -> b: Vale.X64.Memory.b8 -> accu: Vale.X64.Memory.memtaint -> FStar.Pervasives.Lemma (requires i <= LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) /\ (forall (j: Prims.int). {:pattern accu.[ j ]} InteropHeap?.addrs mem b <= j /\ j < InteropHeap?.addrs mem b + i ==> accu.[ j ] = ts b) ) (ensures (let m = Vale.Interop.Base.write_taint i mem ts b accu in let addr = InteropHeap?.addrs mem b in (forall (j: Prims.int). {:pattern m.[ j ]} addr <= j /\ j < addr + LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) ==> m.[ j ] = ts b) /\ (forall (j: Prims.int). {:pattern m.[ j ]} j < addr \/ j >= addr + LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) ==> m.[ j ] == accu.[ j ]))) (decreases LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) - i)
{ "end_col": 47, "end_line": 659, "start_col": 3, "start_line": 650 }
Prims.Tot
val heaps_match (bs:Seq.seq buffer_info) (mt:memtaint) (h1 h2:vale_heap) (id:heaplet_id) : prop0
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "Vale.Lib.BufferViewHelpers", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": false, "full_module": "LowStar.ModifiesPat", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "Vale.Interop.Base", "short_module": "IB" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "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 } ]
false
let heaps_match bs mt h1 h2 id = forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> ( let Mkbuffer_info t b hid tn _ = Seq.index bs i in hid == id ==> buffer_as_seq h1 b == buffer_as_seq h2 b /\ buffer_addr b h1 == buffer_addr b h2 /\ buffer_readable h1 b == buffer_readable h2 b /\ (t == TUInt64 ==> (valid_taint_buf64 b h1 mt tn <==> valid_taint_buf64 b h2 mt tn)) /\ (t == TUInt128 ==> (valid_taint_buf128 b h1 mt tn <==> valid_taint_buf128 b h2 mt tn)) /\ (forall (i:int).{:pattern (buffer_read b i h1) \/ (buffer_read b i h2)} buffer_read b i h1 == buffer_read b i h2))
val heaps_match (bs:Seq.seq buffer_info) (mt:memtaint) (h1 h2:vale_heap) (id:heaplet_id) : prop0 let heaps_match bs mt h1 h2 id =
false
null
false
forall (i: nat). {:pattern Seq.index bs i} i < Seq.length bs ==> (let Mkbuffer_info t b hid tn _ = Seq.index bs i in hid == id ==> buffer_as_seq h1 b == buffer_as_seq h2 b /\ buffer_addr b h1 == buffer_addr b h2 /\ buffer_readable h1 b == buffer_readable h2 b /\ (t == TUInt64 ==> (valid_taint_buf64 b h1 mt tn <==> valid_taint_buf64 b h2 mt tn)) /\ (t == TUInt128 ==> (valid_taint_buf128 b h1 mt tn <==> valid_taint_buf128 b h2 mt tn)) /\ (forall (i: int). {:pattern (buffer_read b i h1)\/(buffer_read b i h2)} buffer_read b i h1 == buffer_read b i h2))
{ "checked_file": "Vale.X64.Memory.fst.checked", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.Views.fsti.checked", "Vale.Interop.Types.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.Arch.Heap.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ModifiesPat.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Map.fsti.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Memory.fst" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Arch.HeapImpl.buffer_info", "Vale.X64.Memory.memtaint", "Vale.Arch.HeapImpl.vale_heap", "Vale.Arch.HeapImpl.heaplet_id", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Arch.HeapTypes_s.base_typ", "Vale.Arch.HeapImpl.buffer", "Vale.Arch.HeapTypes_s.taint", "Vale.Arch.HeapImpl.mutability", "Prims.eq2", "Prims.l_and", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.X64.Memory.buffer_as_seq", "Prims.int", "Vale.X64.Memory.buffer_addr", "Vale.Def.Prop_s.prop0", "Vale.X64.Memory.buffer_readable", "Vale.Arch.HeapTypes_s.TUInt64", "Prims.l_iff", "Vale.X64.Memory.valid_taint_buf64", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.X64.Memory.valid_taint_buf128", "Vale.X64.Memory.buffer_read", "Prims.logical", "FStar.Seq.Base.index" ]
[]
module Vale.X64.Memory include Vale.Interop.Types friend Vale.Arch.Heap open Vale.Def.Opaque_s open Vale.Arch.HeapImpl open Vale.Arch.Heap open Vale.Interop.Base module IB = Vale.Interop.Base module I = Vale.Interop module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module M = LowStar.Modifies open LowStar.ModifiesPat module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down open Vale.Lib.BufferViewHelpers module H = FStar.Heap module S = Vale.X64.Machine_Semantics_s #reset-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" let b8 = IB.b8 unfold let (.[]) = Map.sel unfold let (.[]<-) = Map.upd let get_heaplet_id h = h.heapletId let tuint8 = UInt8.t let tuint16 = UInt16.t let tuint32 = UInt32.t let tuint64 = UInt64.t let v_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : base_typ_as_type t = match t with | TUInt8 -> UInt8.uint_to_t v | TUInt16 -> UInt16.uint_to_t v | TUInt32 -> UInt32.uint_to_t v | TUInt64 -> UInt64.uint_to_t v | TUInt128 -> v let v_to_typ (t:base_typ) (v:base_typ_as_type t) : base_typ_as_vale_type t = match t with | TUInt8 -> UInt8.v v | TUInt16 -> UInt16.v v | TUInt32 -> UInt32.v v | TUInt64 -> UInt64.v v | TUInt128 -> v let lemma_v_to_of_typ (t:base_typ) (v:base_typ_as_vale_type t) : Lemma (ensures v_to_typ t (v_of_typ t v) == v) [SMTPat (v_to_typ t (v_of_typ t v))] = () let uint8_view = Vale.Interop.Views.up_view8 let uint16_view = Vale.Interop.Views.up_view16 let uint32_view = Vale.Interop.Views.up_view32 let uint64_view = Vale.Interop.Views.up_view64 let uint128_view = Vale.Interop.Views.up_view128 let uint_view (t:base_typ) : (v:UV.view UInt8.t (IB.base_typ_as_type t){UV.View?.n v == view_n t}) = match t with | TUInt8 -> uint8_view | TUInt16 -> uint16_view | TUInt32 -> uint32_view | TUInt64 -> uint64_view | TUInt128 -> uint128_view let buffer_as_seq #t h b = let s = UV.as_seq (IB.hs_of_mem (_ih h)) (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) in Vale.Lib.Seqs_s.seq_map (v_to_typ t) s let buffer_readable #t h b = List.memP b (IB.ptrs_of_mem (_ih h)) let buffer_writeable #t b = b.writeable let buffer_length #t b = UV.length (UV.mk_buffer (get_downview b.bsrc) (uint_view t)) let loc = M.loc let loc_none = M.loc_none let loc_union = M.loc_union let loc_buffer #t b = M.loc_buffer b.bsrc let loc_disjoint = M.loc_disjoint let loc_includes = M.loc_includes let modifies s h h' = M.modifies s (_ih h).hs (_ih h').hs /\ h.heapletId == h'.heapletId /\ (_ih h).ptrs == (_ih h').ptrs /\ (_ih h).addrs == (_ih h').addrs /\ HST.equal_domains (_ih h).hs (_ih h').hs let buffer_addr #t b h = IB.addrs_of_mem (_ih h) b open FStar.Mul #set-options "--z3rlimit 20" let index64_heap_aux (s:Seq.lseq UInt8.t 8) (heap:S.machine_heap) (ptr:int) : Lemma (requires forall (j:nat{j < 8}). UInt8.v (Seq.index s j) == heap.[ptr+j]) (ensures UInt64.v (Vale.Interop.Views.get64 s) == S.get_heap_val64 ptr heap) = let open Vale.Def.Words.Seq_s in reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); Vale.Interop.Views.get64_reveal (); S.get_heap_val64_reveal (); Vale.Def.Types_s.le_bytes_to_nat64_reveal () let index_helper (x y:int) (heap:S.machine_heap) : Lemma (requires x == y) (ensures heap.[x] == heap.[y]) = () let index_mul_helper (addr i n j:int) : Lemma (addr + (i * n + j) == addr + n * i + j) = () #set-options "--max_fuel 0 --max_ifuel 0" let index64_get_heap_val64 (h:vale_heap) (b:buffer64{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (Seq.index (buffer_as_seq h b) i == S.get_heap_val64 (buffer_addr b h + scale8 i) heap) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db uint64_view in let ptr = buffer_addr b h + scale8 i in let s = DV.as_seq (_ih h).hs db in let t = TUInt64 in let addr = buffer_addr b h in UV.length_eq ub; UV.as_seq_sel (_ih h).hs ub i; UV.get_sel (_ih h).hs ub i; let s' = Seq.slice s (i*8) (i*8 + 8) in let aux (j:nat{j < 8}) : Lemma (UInt8.v (Seq.index s' j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*8 + j)) == heap.[addr + (i*8+j)]); Seq.lemma_index_slice s (i*8) (i*8+8) j; assert (UInt8.v (Seq.index s' j) == heap.[addr+(i*8+j)]); index_mul_helper addr i 8 j; () in Classical.forall_intro aux; index64_heap_aux s' heap ptr #set-options "--z3rlimit 50" open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Lib.Seqs_s let index128_get_heap_val128_aux (s:Seq.lseq UInt8.t 16) (ptr:int) (heap:S.machine_heap) : Lemma (requires (forall (j:nat) . j < 16 ==> UInt8.v (Seq.index s j) == heap.[ptr+j])) (ensures Vale.Interop.Views.get128 s == Mkfour (S.get_heap_val32 ptr heap) (S.get_heap_val32 (ptr+4) heap) (S.get_heap_val32 (ptr+8) heap) (S.get_heap_val32 (ptr+12) heap)) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); S.get_heap_val32_reveal (); Vale.Interop.Views.get128_reveal (); Vale.Def.Types_s.le_bytes_to_quad32_reveal () let index128_get_heap_val128 (h:vale_heap) (b:buffer128{List.memP b (_ih h).ptrs}) (heap:S.machine_heap{IB.correct_down (_ih h) heap}) (i:nat{i < buffer_length b}) : Lemma (ensures ( let addr = buffer_addr b h in Seq.index (buffer_as_seq h b) i == Mkfour (S.get_heap_val32 (addr + scale16 i) heap) (S.get_heap_val32 (addr + scale16 i+4) heap) (S.get_heap_val32 (addr + scale16 i+8) heap) (S.get_heap_val32 (addr + scale16 i +12) heap) )) = let db = get_downview b.bsrc in let vb = UV.mk_buffer db uint128_view in let ptr = buffer_addr b h + scale16 i in let s = DV.as_seq (_ih h).hs db in let addr = buffer_addr b h in UV.length_eq vb; UV.as_seq_sel (_ih h).hs vb i; UV.get_sel (_ih h).hs vb i; let sl = Seq.slice s (i*16) (i*16+16) in let aux (j:nat{j < 16}) : Lemma (UInt8.v (Seq.index sl j) == heap.[ptr+j]) = assert (UInt8.v (Seq.index s (i*16 + j)) == heap.[addr + (i*16+j)]); Seq.lemma_index_slice s (i*16) (i*16+16) j; assert (UInt8.v (Seq.index sl j) == heap.[addr+(i*16+j)]); index_mul_helper addr i 16 j in Classical.forall_intro aux; index128_get_heap_val128_aux sl ptr heap let modifies_goal_directed s h1 h2 = modifies s h1 h2 let lemma_modifies_goal_directed s h1 h2 = () let buffer_length_buffer_as_seq #t h b = () let same_underlying_seq (#t:base_typ) (h1 h2:vale_heap) (b:buffer t) : Lemma (requires Seq.equal (DV.as_seq (_ih h1).hs (get_downview b.bsrc)) (DV.as_seq (_ih h2).hs (get_downview b.bsrc))) (ensures Seq.equal (buffer_as_seq h1 b) (buffer_as_seq h2 b)) = let db = get_downview b.bsrc in let rec aux (i:nat{i <= buffer_length b}) : Lemma (requires (forall (j:nat{j < i}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j) /\ (Seq.equal (DV.as_seq (_ih h1).hs db) (DV.as_seq (_ih h2).hs db))) (ensures (forall (j:nat{j < buffer_length b}). Seq.index (buffer_as_seq h1 b) j == Seq.index (buffer_as_seq h2 b) j)) (decreases %[(buffer_length b) - i]) = if i = buffer_length b then () else ( let bv = UV.mk_buffer db (uint_view t) in UV.get_sel (_ih h1).hs bv i; UV.get_sel (_ih h2).hs bv i; UV.as_seq_sel (_ih h1).hs bv i; UV.as_seq_sel (_ih h2).hs bv i; aux (i+1) ) in aux 0 let modifies_buffer_elim #t1 b p h h' = let db = get_downview b.bsrc in lemma_dv_equal (down_view b.src) b.bsrc (_ih h).hs (_ih h').hs; same_underlying_seq h h' b; assert (Seq.equal (buffer_as_seq h b) (buffer_as_seq h' b)) let modifies_buffer_addr #t b p h h' = () let modifies_buffer_readable #t b p h h' = () let loc_disjoint_none_r s = M.loc_disjoint_none_r s let loc_disjoint_union_r s s1 s2 = M.loc_disjoint_union_r s s1 s2 let loc_includes_refl s = M.loc_includes_refl s let loc_includes_trans s1 s2 s3 = M.loc_includes_trans s1 s2 s3 let loc_includes_union_r s s1 s2 = M.loc_includes_union_r s s1 s2 let loc_includes_union_l s1 s2 s = M.loc_includes_union_l s1 s2 s let loc_includes_union_l_buffer #t s1 s2 b = M.loc_includes_union_l s1 s2 (loc_buffer b) let loc_includes_none s = M.loc_includes_none s let modifies_refl s h = M.modifies_refl s (_ih h).hs let modifies_goal_directed_refl s h = M.modifies_refl s (_ih h).hs let modifies_loc_includes s1 h h' s2 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 let modifies_trans s12 h1 h2 s23 h3 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs let modifies_goal_directed_trans s12 h1 h2 s13 h3 = modifies_trans s12 h1 h2 s13 h3; modifies_loc_includes s13 h1 h3 (loc_union s12 s13); () let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 = modifies_goal_directed_trans s12 h1 h2 s13 h3 let default_of_typ (t:base_typ) : base_typ_as_vale_type t = allow_inversion base_typ; match t with | TUInt8 -> 0 | TUInt16 -> 0 | TUInt32 -> 0 | TUInt64 -> 0 | TUInt128 -> Vale.Def.Words_s.Mkfour #nat32 0 0 0 0 let buffer_read #t b i h = if i < 0 || i >= buffer_length b then default_of_typ t else Seq.index (buffer_as_seq h b) i let seq_upd (#b:_) (h:HS.mem) (vb:UV.buffer b{UV.live h vb}) (i:nat{i < UV.length vb}) (x:b) : Lemma (Seq.equal (Seq.upd (UV.as_seq h vb) i x) (UV.as_seq (UV.upd h vb i x) vb)) = let old_s = UV.as_seq h vb in let new_s = UV.as_seq (UV.upd h vb i x) vb in let upd_s = Seq.upd old_s i x in let rec aux (k:nat) : Lemma (requires (k <= Seq.length upd_s /\ (forall (j:nat). j < k ==> Seq.index upd_s j == Seq.index new_s j))) (ensures (forall (j:nat). j < Seq.length upd_s ==> Seq.index upd_s j == Seq.index new_s j)) (decreases %[(Seq.length upd_s) - k]) = if k = Seq.length upd_s then () else begin UV.sel_upd vb i k x h; UV.as_seq_sel h vb k; UV.as_seq_sel (UV.upd h vb i x) vb k; aux (k+1) end in aux 0 let buffer_write #t b i v h = if i < 0 || i >= buffer_length b then h else begin let view = uint_view t in let db = get_downview b.bsrc in let bv = UV.mk_buffer db view in UV.upd_modifies (_ih h).hs bv i (v_of_typ t v); UV.upd_equal_domains (_ih h).hs bv i (v_of_typ t v); let hs' = UV.upd (_ih h).hs bv i (v_of_typ t v) in let ih' = InteropHeap (_ih h).ptrs (_ih h).addrs hs' in let mh' = Vale.Interop.down_mem ih' in let h':vale_heap = ValeHeap mh' (Ghost.hide ih') h.heapletId in seq_upd (_ih h).hs bv i (v_of_typ t v); assert (Seq.equal (buffer_as_seq h' b) (Seq.upd (buffer_as_seq h b) i v)); h' end unfold let scale_t (t:base_typ) (index:int) : int = scale_by (view_n t) index // Checks if address addr corresponds to one of the elements of buffer ptr let addr_in_ptr (#t:base_typ) (addr:int) (ptr:buffer t) (h:vale_heap) : Ghost bool (requires True) (ensures fun b -> not b <==> (forall (i:int).{:pattern (scale_t t i)} 0 <= i /\ i < buffer_length ptr ==> addr <> (buffer_addr ptr h) + scale_t t i)) = let n = buffer_length ptr in let base = buffer_addr ptr h in let rec aux (i:nat) : Tot (b:bool{not b <==> (forall j. i <= j /\ j < n ==> addr <> base + scale_t t j)}) (decreases %[n-i]) = if i >= n then false else if addr = base + scale_t t i then true else aux (i+1) in aux 0 let valid_offset (t:base_typ) (n base:nat) (addr:int) (i:nat) = exists j.{:pattern (scale_t t j)} i <= j /\ j < n /\ base + scale_t t j == addr let rec get_addr_in_ptr (t:base_typ) (n base addr:nat) (i:nat) : Ghost nat (requires valid_offset t n base addr i) (ensures fun j -> base + scale_t t j == addr) (decreases %[n - i]) = if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) let valid_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = DV.length (get_downview b.bsrc) % (view_n t) = 0 && addr_in_ptr #t addr b h let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool = valid_buffer t addr b h && b.writeable #set-options "--max_fuel 1 --max_ifuel 1" let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 let rec valid_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h)} List.memP x ps /\ valid_buffer t addr x h)) = match ps with | [] -> false | a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h let valid_mem64 ptr h = valid_mem (TUInt64) ptr h let rec find_valid_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> match o with | None -> not (valid_mem_aux t addr ps h) | Some a -> valid_buffer t addr a h /\ List.memP a ps) = match ps with | [] -> None | a::q -> if valid_buffer t addr a h then Some a else find_valid_buffer_aux t addr q h let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h let rec find_valid_buffer_aux_ps (t:base_typ) (addr:int) (ps:list b8) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs /\ sub_list ps (_ih h1).ptrs) (ensures find_valid_buffer_aux t addr ps h1 == find_valid_buffer_aux t addr ps h2) = match ps with | [] -> () | a::q -> find_valid_buffer_aux_ps t addr q h1 h2 let find_valid_buffer_ps (t:base_typ) (addr:int) (h1:vale_heap) (h2:vale_heap) : Lemma (requires (_ih h1).ptrs == (_ih h2).ptrs) (ensures find_valid_buffer t addr h1 == find_valid_buffer t addr h2) = find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 let find_valid_buffer_valid_offset (t:base_typ) (addr:int) (h:vale_heap) : Lemma (ensures ( match find_valid_buffer t addr h with | None -> True | Some a -> let base = buffer_addr a h in valid_offset t (buffer_length a) base addr 0 )) = () let rec writeable_mem_aux (t:base_typ) addr (ps:list b8) (h:vale_heap) : Ghost bool (requires sub_list ps (_ih h).ptrs) (ensures fun b -> b <==> (exists (x:buffer t). {:pattern (List.memP x ps) \/ (valid_buffer t addr x h) \/ buffer_writeable x} List.memP x ps /\ valid_buffer t addr x h /\ buffer_writeable x)) = match ps with | [] -> false | a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h let rec find_writeable_buffer_aux (t:base_typ) (addr:int) (ps:list b8) (h:vale_heap) : Ghost (option (buffer t)) (requires sub_list ps (_ih h).ptrs) (ensures fun o -> ( match o with | None -> not (writeable_mem_aux t addr ps h) | Some a -> writeable_buffer t addr a h /\ List.memP a ps )) = match ps with | [] -> None | a::q -> if writeable_buffer t addr a h then Some a else find_writeable_buffer_aux t addr q h let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_writeable_buffer_aux t addr (_ih h).ptrs h let load_mem (t:base_typ) (addr:int) (h:vale_heap) : GTot (base_typ_as_vale_type t) = match find_valid_buffer t addr h with | None -> default_of_typ t | Some a -> let base = buffer_addr a h in buffer_read a (get_addr_in_ptr t (buffer_length a) base addr 0) h let load_mem64 ptr h = if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h let length_t_eq (t:base_typ) (b:buffer t) : Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (view_n t)) = let db = get_downview b.bsrc in let ub = UV.mk_buffer db (uint_view t) in UV.length_eq ub; assert (buffer_length b == DV.length db / (view_n t)); FStar.Math.Lib.lemma_div_def (DV.length db) (view_n t) let get_addr_ptr (t:base_typ) (ptr:int) (h:vale_heap) : Ghost (buffer t) (requires valid_mem t ptr h) (ensures fun b -> List.memP b (_ih h).ptrs /\ valid_buffer t ptr b h) = Some?.v (find_valid_buffer t ptr h) #reset-options "--max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0 --z3rlimit 20" let load_buffer_read (t:base_typ) (ptr:int) (h:vale_heap) : Lemma (requires valid_mem t ptr h) (ensures ( let b = get_addr_ptr t ptr h in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in load_mem t ptr h == buffer_read #t b i h )) = () let store_mem (t:base_typ) (addr:int) (v:base_typ_as_vale_type t) (h:vale_heap) : Ghost vale_heap (requires True) (ensures fun h1 -> (_ih h).addrs == (_ih h1).addrs /\ (_ih h).ptrs == (_ih h1).ptrs) = match find_writeable_buffer t addr h with | None -> h | Some a -> let base = buffer_addr a h in buffer_write a (get_addr_in_ptr t (buffer_length a) base addr 0) v h let store_mem64 i v h = if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h let store_buffer_write (t:base_typ) (ptr:int) (v:base_typ_as_vale_type t) (h:vale_heap{writeable_mem t ptr h}) : Lemma (ensures ( let b = Some?.v (find_writeable_buffer t ptr h) in let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in store_mem t ptr v h == buffer_write b i v h )) = () let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h let load_mem128 ptr h = if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h let store_mem128 ptr v h = if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h let lemma_valid_mem64 b i h = () let lemma_writeable_mem64 b i h = () let lemma_store_mem (t:base_typ) (b:buffer t) (i:nat) (v:base_typ_as_vale_type t) (h:vale_heap) : Lemma (requires i < Seq.length (buffer_as_seq h b) /\ buffer_readable h b /\ buffer_writeable b ) (ensures store_mem t (buffer_addr b h + scale_t t i) v h == buffer_write b i v h ) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let view = uint_view t in let addr = buffer_addr b h + scale_t t i in match find_writeable_buffer t addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_load_mem64 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale8 i in let view = uint64_view in match find_valid_buffer TUInt64 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem64 b i v h = lemma_store_mem TUInt64 b i v h let lemma_valid_mem128 b i h = () let lemma_writeable_mem128 b i h = () let lemma_load_mem128 b i h = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; let addr = buffer_addr b h + scale16 i in let view = uint128_view in match find_valid_buffer TUInt128 addr h with | None -> () | Some a -> let da = get_downview a.bsrc in let db = get_downview b.bsrc in UV.length_eq (UV.mk_buffer da view); UV.length_eq (UV.mk_buffer db view); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.disjoint_or_eq_b8 a b); assert (a == b) let lemma_store_mem128 b i v h = lemma_store_mem TUInt128 b i v h open Vale.X64.Machine_s let valid_taint_b8 (b:b8) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 = let addr = (_ih h).addrs b in (forall (i:int).{:pattern (mt.[i])} addr <= i /\ i < addr + DV.length (get_downview b.bsrc) ==> mt.[i] == tn) let valid_taint_buf #t b h mt tn = valid_taint_b8 b h mt tn let apply_taint_buf (#t:base_typ) (b:buffer t) (mem:vale_heap) (memTaint:memtaint) (tn:taint) (i:nat) : Lemma (requires i < DV.length (get_downview b.bsrc) /\ valid_taint_buf b mem memTaint tn) (ensures memTaint.[(_ih mem).addrs b + i] == tn) = () let lemma_valid_taint64 b memTaint mem i t = length_t_eq (TUInt64) b; let ptr = buffer_addr b mem + scale8 i in let aux (i':nat) : Lemma (requires i' >= ptr /\ i' < ptr + 8) (ensures memTaint.[i'] == t) = let extra = scale8 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let lemma_valid_taint128 b memTaint mem i t = length_t_eq (TUInt128) b; let ptr = buffer_addr b mem + scale16 i in let aux i' : Lemma (requires i' >= ptr /\ i' < ptr + 16) (ensures memTaint.[i'] == t) = let extra = scale16 i + i' - ptr in assert (i' == (_ih mem).addrs b + extra); apply_taint_buf b mem memTaint t extra in Classical.forall_intro (Classical.move_requires aux) let same_memTaint (t:base_typ) (b:buffer t) (mem0 mem1:vale_heap) (memT0 memT1:memtaint) : Lemma (requires modifies (loc_buffer b) mem0 mem1 /\ (forall p. Map.sel memT0 p == Map.sel memT1 p)) (ensures memT0 == memT1) = assert (Map.equal memT0 memT1) let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 = same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 let modifies_valid_taint #t b p h h' mt tn = let dv = get_downview b.bsrc in let imp_left () : Lemma (requires valid_taint_buf b h mt tn) (ensures valid_taint_buf b h' mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h').addrs b + i] = tn) = apply_taint_buf b h mt tn i in Classical.forall_intro aux in let imp_right () : Lemma (requires valid_taint_buf b h' mt tn) (ensures valid_taint_buf b h mt tn) = let aux (i:nat{i < DV.length dv}) : Lemma (mt.[(_ih h).addrs b + i] = tn) = apply_taint_buf b h' mt tn i in Classical.forall_intro aux in (Classical.move_requires imp_left()); (Classical.move_requires imp_right()) #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1" let modifies_same_heaplet_id l h1 h2 = () let valid_taint_bufs (mem:vale_heap) (memTaint:memtaint) (ps:list b8) (ts:b8 -> GTot taint) = forall b.{:pattern List.memP b ps} List.memP b ps ==> valid_taint_b8 b mem memTaint (ts b) let rec write_taint_lemma (i:nat) (mem:IB.interop_heap) (ts:b8 -> GTot taint) (b:b8) (accu:memtaint) : Lemma (requires i <= DV.length (get_downview b.bsrc) /\ (forall (j:int).{:pattern accu.[j]} mem.addrs b <= j /\ j < mem.addrs b + i ==> accu.[j] = ts b) ) (ensures ( let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in (forall j.{:pattern m.[j]} addr <= j /\ j < addr + DV.length (get_downview b.bsrc) ==> m.[j] = ts b) /\ (forall j. {:pattern m.[j]} j < addr \/ j >= addr + DV.length (get_downview b.bsrc) ==> m.[j] == accu.[j]))) (decreases %[DV.length (get_downview b.bsrc) - i]) = let m = IB.write_taint i mem ts b accu in let addr = mem.addrs b in if i >= DV.length (get_downview b.bsrc) then () else let new_accu = accu.[addr+i] <- ts b in assert (IB.write_taint i mem ts b accu == IB.write_taint (i + 1) mem ts b new_accu); assert (Set.equal (Map.domain new_accu) (Set.complement Set.empty)); assert (forall j.{:pattern m.[j]} addr <= j /\ j < addr + i + 1 ==> new_accu.[j] == ts b); write_taint_lemma (i + 1) mem ts b new_accu #restart-solver let rec valid_memtaint (mem:vale_heap) (ps:list b8) (ts:b8 -> GTot taint) : Lemma (requires IB.list_disjoint_or_eq ps) (ensures valid_taint_bufs mem (IB.create_memtaint (_ih mem) ps ts) ps ts) = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred; match ps with | [] -> () | b :: q -> assert (List.memP b ps); assert (forall i. {:pattern List.memP i q} List.memP i q ==> List.memP i ps); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (IB.list_disjoint_or_eq q); valid_memtaint mem q ts; assert (IB.create_memtaint (_ih mem) ps ts == IB.write_taint 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts)); write_taint_lemma 0 (_ih mem) ts b (IB.create_memtaint (_ih mem) q ts); opaque_assert (`%list_disjoint_or_eq) list_disjoint_or_eq list_disjoint_or_eq_def (forall p. List.memP p q ==> IB.disjoint_or_eq_b8 p b) let valid_layout_data_buffer (t:base_typ) (b:buffer t) (layout:vale_heap_layout_inner) (hid:heaplet_id) (write:bool) = exists (n:nat).{:pattern (Seq.index layout.vl_buffers n)} n < Seq.length layout.vl_buffers /\ ( let bi = Seq.index layout.vl_buffers n in t == bi.bi_typ /\ b == bi.bi_buffer /\ (write ==> bi.bi_mutable == Mutable) /\ hid == bi.bi_heaplet) [@"opaque_to_smt"] let valid_layout_buffer_id t b layout h_id write = match h_id with | None -> True | Some hid -> layout.vl_inner.vl_heaplets_initialized /\ valid_layout_data_buffer t b layout.vl_inner hid write let inv_heaplet_ids (hs:vale_heaplets) = forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i let inv_heaplet (owns:Set.set int) (h hi:vale_heap) = h.ih.IB.ptrs == hi.ih.IB.ptrs /\ Map.domain h.mh == Map.domain hi.mh /\ (forall (i:int).{:pattern Set.mem i owns \/ Set.mem i (Map.domain h.mh) \/ Map.sel h.mh i \/ Map.sel hi.mh i} Set.mem i owns ==> Set.mem i (Map.domain h.mh) /\ Map.sel h.mh i == Map.sel hi.mh i /\ True ) /\ True // heaplet state matches heap state let inv_buffer_info (bi:buffer_info) (owners:heaplet_id -> Set.set int) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) (modloc:loc) = let t = bi.bi_typ in let hid = bi.bi_heaplet in let hi = Map16.get hs hid in let b = bi.bi_buffer in let owns = owners hid in (bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer b)) /\ buffer_readable h b /\ buffer_as_seq hi b == buffer_as_seq h b /\ (valid_taint_buf b hi mt bi.bi_taint <==> valid_taint_buf b h mt bi.bi_taint) /\ (forall (i:int).{:pattern Set.mem i owns} buffer_addr b h <= i /\ i < buffer_addr b h + DV.length (get_downview b.bsrc) ==> Set.mem i owns) /\ True let inv_heaplets (layout:vale_heap_layout_inner) (h:vale_heap) (hs:vale_heaplets) (mt:memTaint_t) = let bs = layout.vl_buffers in modifies layout.vl_mod_loc layout.vl_old_heap h /\ // modifies for entire heap (forall (i:heaplet_id) (a:int).{:pattern Set.mem a (layout.vl_heaplet_sets i)} layout.vl_heaplet_map a == Some i <==> Set.mem a (layout.vl_heaplet_sets i) ) /\ (forall (i:heaplet_id).{:pattern (Map16.sel hs i)} inv_heaplet (layout.vl_heaplet_sets i) h (Map16.sel hs i)) /\ (forall (i:nat).{:pattern (Seq.index bs i)} i < Seq.length bs ==> inv_buffer_info (Seq.index bs i) layout.vl_heaplet_sets h hs mt layout.vl_mod_loc) /\ (forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)} i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)) /\ True let is_initial_heap layout h = h == layout.vl_inner.vl_old_heap /\ not layout.vl_inner.vl_heaplets_initialized let mem_inv h = h.vf_heap.heapletId == None /\ inv_heaplet_ids h.vf_heaplets /\ (if h.vf_layout.vl_inner.vl_heaplets_initialized then inv_heaplets h.vf_layout.vl_inner h.vf_heap h.vf_heaplets h.vf_layout.vl_taint else h.vf_heaplets == empty_vale_heaplets h.vf_layout.vl_inner.vl_old_heap ) let layout_heaplets_initialized layout = layout.vl_heaplets_initialized let layout_old_heap layout = layout.vl_old_heap let layout_modifies_loc layout = layout.vl_mod_loc let layout_buffers layout = layout.vl_buffers
false
true
Vale.X64.Memory.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val heaps_match (bs:Seq.seq buffer_info) (mt:memtaint) (h1 h2:vale_heap) (id:heaplet_id) : prop0
[]
Vale.X64.Memory.heaps_match
{ "file_name": "vale/code/arch/x64/Vale.X64.Memory.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info -> mt: Vale.X64.Memory.memtaint -> h1: Vale.Arch.HeapImpl.vale_heap -> h2: Vale.Arch.HeapImpl.vale_heap -> id: Vale.Arch.HeapImpl.heaplet_id -> Vale.Def.Prop_s.prop0
{ "end_col": 48, "end_line": 768, "start_col": 2, "start_line": 759 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let state_sha2_512 = Hacl.Streaming.MD.state_64
let state_sha2_512 =
false
null
false
Hacl.Streaming.MD.state_64
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.MD.state_64" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_sha2_512 : Type0
[]
Hacl.Streaming.SHA2.state_sha2_512
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 47, "end_line": 50, "start_col": 21, "start_line": 50 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let state_sha2_384 = Hacl.Streaming.MD.state_64
let state_sha2_384 =
false
null
false
Hacl.Streaming.MD.state_64
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.MD.state_64" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_sha2_384 : Type0
[]
Hacl.Streaming.SHA2.state_sha2_384
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 47, "end_line": 49, "start_col": 21, "start_line": 49 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let state_sha2_256 = Hacl.Streaming.MD.state_32
let state_sha2_256 =
false
null
false
Hacl.Streaming.MD.state_32
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.MD.state_32" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_sha2_256 : Type0
[]
Hacl.Streaming.SHA2.state_sha2_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 47, "end_line": 48, "start_col": 21, "start_line": 48 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let state_sha2_224 = Hacl.Streaming.MD.state_32
let state_sha2_224 =
false
null
false
Hacl.Streaming.MD.state_32
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.MD.state_32" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_sha2_224 : Type0
[]
Hacl.Streaming.SHA2.state_sha2_224
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 47, "end_line": 47, "start_col": 21, "start_line": 47 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit)
let create_in_256 =
false
null
false
F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.create_in", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_256", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_256", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val create_in_256 : Hacl.Streaming.Functor.create_in_st Hacl.Streaming.SHA2.hacl_sha2_256 () (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.create_in_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.create_in_st Hacl.Streaming.SHA2.hacl_sha2_256 () (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 83, "end_line": 70, "start_col": 20, "start_line": 70 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit)
let update_224_256 =
false
null
false
F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.update", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_256", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_256", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ]
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_224_256 : Hacl.Streaming.Functor.update_st Hacl.Streaming.SHA2.hacl_sha2_256 (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.update_224_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.update_st Hacl.Streaming.SHA2.hacl_sha2_256 (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 90, "end_line": 85, "start_col": 21, "start_line": 85 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hacl_sha2_512 = hacl_md SHA2_512
let hacl_sha2_512 =
false
null
false
hacl_md SHA2_512
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.MD.hacl_md", "Spec.Hash.Definitions.SHA2_512" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384
false
true
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hacl_sha2_512 : Hacl.Streaming.Interface.block Prims.unit
[]
Hacl.Streaming.SHA2.hacl_sha2_512
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Interface.block Prims.unit
{ "end_col": 36, "end_line": 35, "start_col": 20, "start_line": 35 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit)
let create_in_224 =
false
null
false
F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.create_in", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_224", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_224", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val create_in_224 : Hacl.Streaming.Functor.create_in_st Hacl.Streaming.SHA2.hacl_sha2_224 () (Stateful?.s Hacl.Streaming.SHA2.state_t_224 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.create_in_224
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.create_in_st Hacl.Streaming.SHA2.hacl_sha2_224 () (Stateful?.s Hacl.Streaming.SHA2.state_t_224 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 83, "end_line": 129, "start_col": 20, "start_line": 129 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let free_512 = F.free hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit)
let free_512 =
false
null
false
F.free hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.free", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_512", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_512", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // -------- inline_for_extraction noextract let alloca_512 = F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let create_in_512 = F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_512`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_512 = F.copy hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let init_512 = F.init hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ CInline ] private let update_384_512 = F.update hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_512` (since the last call to `init_512`) exceeds 2^125-1 bytes. This function is identical to the update function for SHA2_384."; ] let update_512: F.update_st hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) = fun p input input_len -> update_384_512 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 64 bytes. The state remains valid after a call to `finish_512`, meaning the user may feed more data into the hash via `update_512`. (The finish_512 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_512 = F.mk_finish hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_512`. This function is identical to the free function for SHA2_384.";
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val free_512 : Hacl.Streaming.Functor.free_st Hacl.Streaming.SHA2.hacl_sha2_512 (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.free_512
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.free_st Hacl.Streaming.SHA2.hacl_sha2_512 (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 82, "end_line": 196, "start_col": 15, "start_line": 196 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit)
let init_224 =
false
null
false
F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.init", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_224", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_224", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit)
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_224 : Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_224 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_224 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.init_224
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_224 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_224 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 82, "end_line": 130, "start_col": 15, "start_line": 130 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let alloca_512 = F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit)
let alloca_512 =
false
null
false
F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.alloca", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_512", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_512", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // --------
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val alloca_512 : Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_512 () (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.alloca_512
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_512 () (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 77, "end_line": 160, "start_col": 17, "start_line": 160 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let init_384 = F.init hacl_sha2_384 (G.hide ()) (state_t_384.s ()) (G.erased unit)
let init_384 =
false
null
false
F.init hacl_sha2_384 (G.hide ()) (state_t_384.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.init", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_384", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_384", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // -------- inline_for_extraction noextract let alloca_512 = F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let create_in_512 = F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_512`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_512 = F.copy hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let init_512 = F.init hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ CInline ] private let update_384_512 = F.update hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_512` (since the last call to `init_512`) exceeds 2^125-1 bytes. This function is identical to the update function for SHA2_384."; ] let update_512: F.update_st hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) = fun p input input_len -> update_384_512 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 64 bytes. The state remains valid after a call to `finish_512`, meaning the user may feed more data into the hash via `update_512`. (The finish_512 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_512 = F.mk_finish hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_512`. This function is identical to the free function for SHA2_384."; ] let free_512 = F.free hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 64 bytes."] val hash_512: Hacl.Hash.Definitions.hash_st SHA2_512 let hash_512 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_512) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_512 #M32 sha512_init sha512_update_nblocks sha512_update_last sha512_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_512 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-384 // -------- inline_for_extraction noextract let alloca_384 = F.alloca hacl_sha2_384 () (state_t_384.s ()) (G.erased unit)
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_384 : Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_384 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_384 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.init_384
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_384 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_384 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 82, "end_line": 219, "start_col": 15, "start_line": 219 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let finish_512 = F.mk_finish hacl_sha2_512 () (state_t_512.s ()) (G.erased unit)
let finish_512 =
false
null
false
F.mk_finish hacl_sha2_512 () (state_t_512.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.mk_finish", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_512", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_512", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // -------- inline_for_extraction noextract let alloca_512 = F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let create_in_512 = F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_512`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_512 = F.copy hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let init_512 = F.init hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ CInline ] private let update_384_512 = F.update hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_512` (since the last call to `init_512`) exceeds 2^125-1 bytes. This function is identical to the update function for SHA2_384."; ] let update_512: F.update_st hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) = fun p input input_len -> update_384_512 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 64 bytes. The state remains valid after a call to `finish_512`, meaning the user may feed more data into the hash via `update_512`. (The finish_512 function operates on an internal copy of
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val finish_512 : Hacl.Streaming.Functor.finish_st Hacl.Streaming.SHA2.hacl_sha2_512 () (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.finish_512
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.finish_st Hacl.Streaming.SHA2.hacl_sha2_512 () (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 80, "end_line": 189, "start_col": 17, "start_line": 189 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let state_t_384 = state_t SHA2_384
let state_t_384 =
false
null
false
state_t SHA2_384
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.MD.state_t", "Spec.Hash.Definitions.SHA2_384" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256
false
true
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_t_384 : Hacl.Streaming.Interface.stateful Prims.unit
[]
Hacl.Streaming.SHA2.state_t_384
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Interface.stateful Prims.unit
{ "end_col": 34, "end_line": 42, "start_col": 18, "start_line": 42 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit)
let free_256 =
false
null
false
F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.free", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_256", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_256", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`.
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val free_256 : Hacl.Streaming.Functor.free_st Hacl.Streaming.SHA2.hacl_sha2_256 (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.free_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.free_st Hacl.Streaming.SHA2.hacl_sha2_256 (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 82, "end_line": 107, "start_col": 15, "start_line": 107 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let create_in_512 = F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit)
let create_in_512 =
false
null
false
F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.create_in", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_512", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_512", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // -------- inline_for_extraction noextract
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val create_in_512 : Hacl.Streaming.Functor.create_in_st Hacl.Streaming.SHA2.hacl_sha2_512 () (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.create_in_512
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.create_in_st Hacl.Streaming.SHA2.hacl_sha2_512 () (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 83, "end_line": 161, "start_col": 20, "start_line": 161 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit)
let init_256 =
false
null
false
F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.init", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_256", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_256", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_256 : Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_256 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.init_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_256 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 82, "end_line": 81, "start_col": 15, "start_line": 81 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let init_512 = F.init hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit)
let init_512 =
false
null
false
F.init hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.init", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_512", "FStar.Ghost.hide", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_512", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // -------- inline_for_extraction noextract let alloca_512 = F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let create_in_512 = F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_512`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_512 = F.copy hacl_sha2_512 () (state_t_512.s ()) (G.erased unit)
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_512 : Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_512 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.init_512
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.init_st Hacl.Streaming.SHA2.hacl_sha2_512 (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Stateful?.s Hacl.Streaming.SHA2.state_t_512 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 82, "end_line": 170, "start_col": 15, "start_line": 170 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let alloca_384 = F.alloca hacl_sha2_384 () (state_t_384.s ()) (G.erased unit)
let alloca_384 =
false
null
false
F.alloca hacl_sha2_384 () (state_t_384.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.alloca", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_384", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_384", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // -------- inline_for_extraction noextract let alloca_512 = F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let create_in_512 = F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_512`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_512 = F.copy hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let init_512 = F.init hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ CInline ] private let update_384_512 = F.update hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_512` (since the last call to `init_512`) exceeds 2^125-1 bytes. This function is identical to the update function for SHA2_384."; ] let update_512: F.update_st hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) = fun p input input_len -> update_384_512 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 64 bytes. The state remains valid after a call to `finish_512`, meaning the user may feed more data into the hash via `update_512`. (The finish_512 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_512 = F.mk_finish hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_512`. This function is identical to the free function for SHA2_384."; ] let free_512 = F.free hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 64 bytes."] val hash_512: Hacl.Hash.Definitions.hash_st SHA2_512 let hash_512 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_512) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_512 #M32 sha512_init sha512_update_nblocks sha512_update_last sha512_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_512 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-384 // --------
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val alloca_384 : Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_384 () (Stateful?.s Hacl.Streaming.SHA2.state_t_384 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.alloca_384
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_384 () (Stateful?.s Hacl.Streaming.SHA2.state_t_384 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 77, "end_line": 217, "start_col": 17, "start_line": 217 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit)
let alloca_256 =
false
null
false
F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.alloca", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_256", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_256", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // --------
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val alloca_256 : Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_256 () (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.alloca_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_256 () (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 77, "end_line": 65, "start_col": 17, "start_line": 65 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit)
let finish_256 =
false
null
false
F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.mk_finish", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_256", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_256", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val finish_256 : Hacl.Streaming.Functor.finish_st Hacl.Streaming.SHA2.hacl_sha2_256 () (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.finish_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.finish_st Hacl.Streaming.SHA2.hacl_sha2_256 () (Stateful?.s Hacl.Streaming.SHA2.state_t_256 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 80, "end_line": 101, "start_col": 17, "start_line": 101 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2.Scalar32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let finish_384 = F.mk_finish hacl_sha2_384 () (state_t_384.s ()) (G.erased unit)
let finish_384 =
false
null
false
F.mk_finish hacl_sha2_384 () (state_t_384.s ()) (G.erased unit)
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.mk_finish", "Prims.unit", "Hacl.Streaming.SHA2.hacl_sha2_384", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "Hacl.Streaming.SHA2.state_t_384", "FStar.Ghost.erased" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224 inline_for_extraction noextract let state_t_256 = state_t SHA2_256 inline_for_extraction noextract let state_t_384 = state_t SHA2_384 inline_for_extraction noextract let state_t_512 = state_t SHA2_512 /// Type abbreviations - for pretty code generation let state_sha2_224 = Hacl.Streaming.MD.state_32 let state_sha2_256 = Hacl.Streaming.MD.state_32 let state_sha2_384 = Hacl.Streaming.MD.state_64 let state_sha2_512 = Hacl.Streaming.MD.state_64 open Lib.Buffer open Lib.IntTypes open Lib.NTuple open Lib.MultiBuffer open Hacl.Spec.SHA2.Vec open Hacl.SHA2.Scalar32 open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST // SHA2-256 // -------- inline_for_extraction noextract let alloca_256 = F.alloca hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Allocate initial state for the SHA2_256 hash. The state is to be freed by calling `free_256`."] let create_in_256 = F.create_in hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_256`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_256 = F.copy hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Reset an existing state to the initial hash state with empty data."] let init_256 = F.init hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ CInline ] private let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_256` (since the last call to `init_256`) exceeds 2^61-1 bytes. This function is identical to the update function for SHA2_224."; ] let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 32 bytes. The state remains valid after a call to `finish_256`, meaning the user may feed more data into the hash via `update_256`. (The finish_256 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_256 = F.mk_finish hacl_sha2_256 () (state_t_256.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_256`. This function is identical to the free function for SHA2_224."] let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 32 bytes."] val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 let hash_256 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_256) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_256 #M32 sha256_init sha256_update_nblocks sha256_update_last sha256_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-224 // -------- inline_for_extraction noextract let alloca_224 = F.alloca hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let create_in_224 = F.create_in hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let init_224 = F.init hacl_sha2_224 (G.hide ()) (state_t_224.s ()) (G.erased unit) // We assume verified clients will rely on Spec.SHA2.Lemmas to prove that update_224 has the same effect as update_256. let update_224: F.update_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p input input_len -> update_224_256 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 28 bytes. The state remains valid after a call to `finish_224`, meaning the user may feed more data into the hash via `update_224`."] let finish_224 = F.mk_finish hacl_sha2_224 () (state_t_224.s ()) (G.erased unit) let free_224: F.free_st hacl_sha2_256 (G.hide ()) (state_t_256.s ()) (G.erased unit) = fun p -> free_256 p [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 28 bytes."] val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 let hash_224 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_224) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_224 #M32 sha224_init sha224_update_nblocks sha224_update_last sha224_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-512 // -------- inline_for_extraction noextract let alloca_512 = F.alloca hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let create_in_512 = F.create_in hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Copies the state passed as argument into a newly allocated state (deep copy). The state is to be freed by calling `free_512`. Cloning the state this way is useful, for instance, if your control-flow diverges and you need to feed more (different) data into the hash in each branch."] let copy_512 = F.copy hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) let init_512 = F.init hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ CInline ] private let update_384_512 = F.update hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Feed an arbitrary amount of data into the hash. This function returns 0 for success, or 1 if the combined length of all of the data passed to `update_512` (since the last call to `init_512`) exceeds 2^125-1 bytes. This function is identical to the update function for SHA2_384."; ] let update_512: F.update_st hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) = fun p input input_len -> update_384_512 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 64 bytes. The state remains valid after a call to `finish_512`, meaning the user may feed more data into the hash via `update_512`. (The finish_512 function operates on an internal copy of the state and therefore does not invalidate the client-held state `p`.)"] let finish_512 = F.mk_finish hacl_sha2_512 () (state_t_512.s ()) (G.erased unit) [@@ Comment "Free a state allocated with `create_in_512`. This function is identical to the free function for SHA2_384."; ] let free_512 = F.free hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) [@@ Comment "Hash `input`, of len `input_len`, into `dst`, an array of 64 bytes."] val hash_512: Hacl.Hash.Definitions.hash_st SHA2_512 let hash_512 input input_len dst = [@inline_let] let dst: lbuffer uint8 (Hacl.Hash.Definitions.hash_len SHA2_512) = dst in let ib = ntup1 input in let rb = ntup1 dst in let h0 = ST.get() in loc_multi1 rb; hash #SHA2_512 #M32 sha512_init sha512_update_nblocks sha512_update_last sha512_finish rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_512 #M32 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst) // SHA2-384 // -------- inline_for_extraction noextract let alloca_384 = F.alloca hacl_sha2_384 () (state_t_384.s ()) (G.erased unit) let create_in_384 = F.create_in hacl_sha2_384 () (state_t_384.s ()) (G.erased unit) let init_384 = F.init hacl_sha2_384 (G.hide ()) (state_t_384.s ()) (G.erased unit) let update_384: F.update_st hacl_sha2_512 (G.hide ()) (state_t_512.s ()) (G.erased unit) = fun p input input_len -> update_384_512 p input input_len [@@ Comment "Write the resulting hash into `dst`, an array of 48 bytes. The state remains valid after a call to `finish_384`, meaning the user may feed more data into
false
false
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val finish_384 : Hacl.Streaming.Functor.finish_st Hacl.Streaming.SHA2.hacl_sha2_384 () (Stateful?.s Hacl.Streaming.SHA2.state_t_384 ()) (FStar.Ghost.erased Prims.unit)
[]
Hacl.Streaming.SHA2.finish_384
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.finish_st Hacl.Streaming.SHA2.hacl_sha2_384 () (Stateful?.s Hacl.Streaming.SHA2.state_t_384 ()) (FStar.Ghost.erased Prims.unit)
{ "end_col": 80, "end_line": 226, "start_col": 17, "start_line": 226 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Streaming.MD", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Interface", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let state_t_256 = state_t SHA2_256
let state_t_256 =
false
null
false
state_t SHA2_256
{ "checked_file": "Hacl.Streaming.SHA2.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.MD.fst.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.SHA2.Scalar32.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.SHA2.fst" }
[ "total" ]
[ "Hacl.Streaming.MD.state_t", "Spec.Hash.Definitions.SHA2_256" ]
[]
module Hacl.Streaming.SHA2 // NOTE: if you get errors trying to load this file in interactive mode because // a tactic fails in Hacl.Streaming.MD (even though Hacl.Streaming.MD works // totally fine in interactive mode!!), run: // NODEPEND=1 make -j obj/Hacl.Streaming.MD.fst.checked open FStar.HyperStack.ST /// A streaming version of MD-based hashes #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" module G = FStar.Ghost module F = Hacl.Streaming.Functor open Spec.Hash.Definitions open Hacl.Streaming.Interface open Hacl.Streaming.MD /// Instantiations of the streaming functor for specialized SHA2 algorithms. /// /// Some remarks: /// /// - we don't bother with using the abstraction feature since we verified /// clients like miTLS go through EverCrypt.Hash.Incremental inline_for_extraction noextract let hacl_sha2_224 = hacl_md SHA2_224 inline_for_extraction noextract let hacl_sha2_256 = hacl_md SHA2_256 inline_for_extraction noextract let hacl_sha2_384 = hacl_md SHA2_384 inline_for_extraction noextract let hacl_sha2_512 = hacl_md SHA2_512 inline_for_extraction noextract let state_t_224 = state_t SHA2_224
false
true
Hacl.Streaming.SHA2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_t_256 : Hacl.Streaming.Interface.stateful Prims.unit
[]
Hacl.Streaming.SHA2.state_t_256
{ "file_name": "code/streaming/Hacl.Streaming.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Interface.stateful Prims.unit
{ "end_col": 34, "end_line": 40, "start_col": 18, "start_line": 40 }