file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.X64.Memory.fst | Vale.X64.Memory.writeable_buffer | val writeable_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool | val writeable_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool | let writeable_buffer (t:base_typ) (addr:int) (b:b8) (h:vale_heap) : GTot bool =
valid_buffer t addr b h && b.writeable | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 345,
"start_col": 0,
"start_line": 344
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.int",
"Vale.X64.Memory.b8",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_AmpAmp",
"Vale.X64.Memory.valid_buffer",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Prims.bool"
] | [] | false | false | false | false | false | let writeable_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool =
| valid_buffer t addr b h && b.writeable | false |
Vale.X64.Memory.fst | Vale.X64.Memory.sub_list | val sub_list : p1: Prims.list 'a -> p2: Prims.list 'a -> Prims.logical | let sub_list (p1 p2:list 'a) = forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 100,
"end_line": 348,
"start_col": 0,
"start_line": 348
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | p1: Prims.list 'a -> p2: Prims.list 'a -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.List.Tot.Base.memP",
"Prims.logical"
] | [] | false | false | false | true | true | let sub_list (p1 p2: list 'a) =
| forall x. {:pattern List.memP x p2} List.memP x p1 ==> List.memP x p2 | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.loc_includes_union_l | 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)) | 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 = M.loc_includes_union_l s1 s2 s | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 238,
"start_col": 0,
"start_line": 238
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"LowStar.Monotonic.Buffer.loc_includes_union_l",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_union_l s1 s2 s =
| M.loc_includes_union_l s1 s2 s | false |
Vale.X64.Memory.fst | Vale.X64.Memory.loc_includes_refl | val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)] | val loc_includes_refl (s:loc) : Lemma
(loc_includes s s)
[SMTPat (loc_includes s s)] | let loc_includes_refl s = M.loc_includes_refl s | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 235,
"start_col": 0,
"start_line": 235
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | s: Vale.X64.Memory.loc
-> FStar.Pervasives.Lemma (ensures Vale.X64.Memory.loc_includes s s)
[SMTPat (Vale.X64.Memory.loc_includes s s)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"LowStar.Monotonic.Buffer.loc_includes_refl",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_refl s =
| M.loc_includes_refl s | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_mem64 | val valid_mem64 (ptr:int) (h:vale_heap) : GTot bool | val valid_mem64 (ptr:int) (h:vale_heap) : GTot bool | let valid_mem64 ptr h = valid_mem (TUInt64) ptr h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 360,
"start_col": 0,
"start_line": 360
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.valid_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.bool"
] | [] | false | false | false | false | false | let valid_mem64 ptr h =
| valid_mem (TUInt64) ptr h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.loc_disjoint_union_r | 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))] | 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 = M.loc_disjoint_union_r s s1 s2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 234,
"start_col": 0,
"start_line": 234
} | 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' = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"LowStar.Monotonic.Buffer.loc_disjoint_union_r",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_disjoint_union_r s s1 s2 =
| M.loc_disjoint_union_r s s1 s2 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.loc_includes_trans | val loc_includes_trans (s1 s2 s3:loc) : Lemma
(requires (loc_includes s1 s2 /\ loc_includes s2 s3))
(ensures (loc_includes s1 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 = M.loc_includes_trans s1 s2 s3 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 236,
"start_col": 0,
"start_line": 236
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"LowStar.Monotonic.Buffer.loc_includes_trans",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_trans s1 s2 s3 =
| M.loc_includes_trans s1 s2 s3 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.loc_includes_none | val loc_includes_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)] | val loc_includes_none (s:loc) : Lemma
(loc_includes s loc_none)
[SMTPat (loc_includes s loc_none)] | let loc_includes_none s = M.loc_includes_none s | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 240,
"start_col": 0,
"start_line": 240
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"LowStar.Monotonic.Buffer.loc_includes_none",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_none s =
| M.loc_includes_none s | false |
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_goal_directed_refl | val modifies_goal_directed_refl (s:loc) (h:vale_heap) : Lemma
(modifies_goal_directed s h h)
[SMTPat (modifies_goal_directed s h h)] | 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 = M.modifies_refl s (_ih h).hs | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 242,
"start_col": 0,
"start_line": 242
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)] | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let modifies_goal_directed_refl s h =
| M.modifies_refl s (_ih h).hs | false |
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_refl | val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies s h h)] | val modifies_refl (s:loc) (h:vale_heap) : Lemma
(modifies s h h)
[SMTPat (modifies s h h)] | let modifies_refl s h = M.modifies_refl s (_ih h).hs | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 241,
"start_col": 0,
"start_line": 241
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)] | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let modifies_refl s h =
| M.modifies_refl s (_ih h).hs | false |
Vale.X64.Memory.fst | Vale.X64.Memory.loc_includes_union_l_buffer | 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))] | 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 = M.loc_includes_union_l s1 s2 (loc_buffer b) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 239,
"start_col": 0,
"start_line": 239
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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))
] | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let loc_includes_union_l_buffer #t s1 s2 b =
| M.loc_includes_union_l s1 s2 (loc_buffer b) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_buffer_elim | 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)];
]] | 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' =
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)) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 228,
"start_col": 0,
"start_line": 224
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)]
]
] | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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)) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.default_of_typ | val default_of_typ (t: base_typ) : base_typ_as_vale_type t | 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 =
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 260,
"start_col": 0,
"start_line": 253
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> Vale.X64.Memory.base_typ_as_vale_type t | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.loc_includes_union_r | 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))] | 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 = M.loc_includes_union_r s s1 s2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 237,
"start_col": 0,
"start_line": 237
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"LowStar.Monotonic.Buffer.loc_includes_union_r",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_includes_union_r s s1 s2 =
| M.loc_includes_union_r s s1 s2 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.same_underlying_seq | 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)) | 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))
=
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 222,
"start_col": 0,
"start_line": 203
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_trans | 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)) | 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 = M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 244,
"start_col": 0,
"start_line": 244
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let modifies_trans s12 h1 h2 s23 h3 =
| M.modifies_trans s12 (_ih h1).hs (_ih h2).hs s23 (_ih h3).hs | false |
Vale.X64.Memory.fst | Vale.X64.Memory.loc_disjoint_none_r | val loc_disjoint_none_r (s:loc) : Lemma
(ensures (loc_disjoint s loc_none))
[SMTPat (loc_disjoint s loc_none)] | 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 = M.loc_disjoint_none_r s | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 233,
"start_col": 0,
"start_line": 233
} | 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' = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"LowStar.Monotonic.Buffer.loc_disjoint_none_r",
"Prims.unit"
] | [] | true | false | true | false | false | let loc_disjoint_none_r s =
| M.loc_disjoint_none_r s | false |
Hacl.Impl.Curve25519.Generic.fst | Hacl.Impl.Curve25519.Generic.ladder1_ | val ladder1_:
#s:field_spec
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 p01_tmp1 /\ live h0 tmp2 /\ disjoint p01_tmp1 tmp2 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == M.montgomery_ladder1_1 (fget_xz h0 nq))) | val ladder1_:
#s:field_spec
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 p01_tmp1 /\ live h0 tmp2 /\ disjoint p01_tmp1 tmp2 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == M.montgomery_ladder1_1 (fget_xz h0 nq))) | let ladder1_ #s p01_tmp1 tmp2 =
let nq : point s = sub p01_tmp1 0ul (2ul *! nlimb s) in
let tmp1 = sub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) in
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) == tmp1);
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2 | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Generic.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 327,
"start_col": 0,
"start_line": 318
} | module Hacl.Impl.Curve25519.Generic
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Curve25519.Fields
include Hacl.Impl.Curve25519.Finv
include Hacl.Impl.Curve25519.AddAndDouble
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
module LSeq = Lib.Sequence
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Spec.Curve25519
module M = Hacl.Spec.Curve25519.AddAndDouble
module Lemmas = Hacl.Spec.Curve25519.Field64.Lemmas
friend Lib.LoopCombinators
#set-options "--z3rlimit 30 --fuel 0 --ifuel 1 --using_facts_from '* -FStar.Seq -Hacl.Spec.*' --record_options"
//#set-options "--debug Hacl.Impl.Curve25519.Generic --debug_level ExtractNorm"
inline_for_extraction noextract
let scalar = lbuffer uint8 32ul
inline_for_extraction noextract
val scalar_bit:
s:scalar
-> n:size_t{v n < 256}
-> Stack uint64
(requires fun h0 -> live h0 s)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.ith_bit (as_seq h0 s) (v n) /\ v r <= 1)
let scalar_bit s n =
let h0 = ST.get () in
mod_mask_lemma ((LSeq.index (as_seq h0 s) (v n / 8)) >>. (n %. 8ul)) 1ul;
assert_norm (1 = pow2 1 - 1);
assert (v (mod_mask #U8 #SEC 1ul) == v (u8 1));
to_u64 ((s.(n /. 8ul) >>. (n %. 8ul)) &. u8 1)
inline_for_extraction noextract
val decode_point:
#s:field_spec
-> o:point s
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
state_inv_t h1 (get_x o) /\ state_inv_t h1 (get_z o) /\
fget_x h1 o == S.decodePoint (as_seq h0 i) /\ fget_z h1 o == 1)
[@ Meta.Attribute.specialize ]
let decode_point #s o i =
push_frame();
let tmp = create 4ul (u64 0) in
let h0 = ST.get () in
uints_from_bytes_le #U64 tmp i;
let h1 = ST.get () in
BSeq.uints_from_bytes_le_nat_lemma #U64 #SEC #4 (as_seq h0 i);
assert (BSeq.nat_from_intseq_le (as_seq h1 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i));
let tmp3 = tmp.(3ul) in
tmp.(3ul) <- tmp3 &. u64 0x7fffffffffffffff;
mod_mask_lemma tmp3 63ul;
assert_norm (0x7fffffffffffffff = pow2 63 - 1);
assert (v (mod_mask #U64 #SEC 63ul) == v (u64 0x7fffffffffffffff));
let h2 = ST.get () in
assert (v (LSeq.index (as_seq h2 tmp) 3) < pow2 63);
Lemmas.lemma_felem64_mod255 (as_seq h1 tmp);
assert (BSeq.nat_from_intseq_le (as_seq h2 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i) % pow2 255);
let x : felem s = sub o 0ul (nlimb s) in
let z : felem s = sub o (nlimb s) (nlimb s) in
set_one z;
load_felem x tmp;
pop_frame()
val encode_point:
#s:field_spec
-> o:lbuffer uint8 32ul
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ disjoint o i /\
state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.encodePoint (fget_x h0 i, fget_z h0 i))
[@ Meta.Attribute.specialize ]
let encode_point #s o i =
push_frame();
let x : felem s = sub i 0ul (nlimb s) in
let z : felem s = sub i (nlimb s) (nlimb s) in
let tmp = create_felem s in
let u64s = create 4ul (u64 0) in
let tmp_w = create (2ul `FStar.UInt32.mul` ((nwide s) <: FStar.UInt32.t)) (wide_zero s) in
let h0 = ST.get () in
finv tmp z tmp_w;
fmul tmp tmp x tmp_w;
let h1 = ST.get () in
assert (feval h1 tmp == S.fmul (S.fpow (feval h0 z) (pow2 255 - 21)) (feval h0 x));
assert (feval h1 tmp == S.fmul (feval h0 x) (S.fpow (feval h0 z) (pow2 255 - 21)));
store_felem u64s tmp;
let h2 = ST.get () in
assert (as_seq h2 u64s == BSeq.nat_to_intseq_le 4 (feval h1 tmp));
uints_to_bytes_le #U64 4ul o u64s;
let h3 = ST.get () in
BSeq.uints_to_bytes_le_nat_lemma #U64 #SEC 4 (feval h1 tmp);
assert (as_seq h3 o == BSeq.nat_to_bytes_le 32 (feval h1 tmp));
pop_frame()
// TODO: why re-define the signature here?
val cswap2:
#s:field_spec
-> bit:uint64{v bit <= 1}
-> p1:felem2 s
-> p2:felem2 s
-> Stack unit
(requires fun h0 ->
live h0 p1 /\ live h0 p2 /\ disjoint p1 p2)
(ensures fun h0 _ h1 ->
modifies (loc p1 |+| loc p2) h0 h1 /\
(v bit == 1 ==> as_seq h1 p1 == as_seq h0 p2 /\ as_seq h1 p2 == as_seq h0 p1) /\
(v bit == 0 ==> as_seq h1 p1 == as_seq h0 p1 /\ as_seq h1 p2 == as_seq h0 p2) /\
(fget_xz h1 p1, fget_xz h1 p2) == S.cswap2 bit (fget_xz h0 p1) (fget_xz h0 p2))
[@ Meta.Attribute.inline_ ]
let cswap2 #s bit p0 p1 =
C.cswap2 #s bit p0 p1
val ladder_step:
#s:field_spec
-> k:scalar
-> q:point s
-> i:size_t{v i < 251}
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
v (LSeq.index (as_seq h0 bit) 0) <= 1 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let (p0, p1, b) = S.ladder_step (as_seq h0 k) (fget_xz h0 q) (v i)
(fget_xz h0 nq, fget_xz h0 nq_p1, LSeq.index (as_seq h0 bit) 0) in
p0 == fget_xz h1 nq /\ p1 == fget_xz h1 nq_p1 /\
b == LSeq.index (as_seq h1 bit) 0 /\
v (LSeq.index (as_seq h1 bit) 0) <= 1 /\
state_inv_t h1 (get_x q) /\ state_inv_t h1 (get_z q) /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1)))
#push-options "--z3rlimit 200 --fuel 0 --ifuel 1"
[@ Meta.Attribute.inline_ ]
let ladder_step #s k q i p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let swap : lbuffer uint64 1ul = sub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let nq = sub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = sub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap (8ul *! nlimb s) 1ul == swap);
let h0 = ST.get () in
let bit = scalar_bit k (253ul -. i) in
assert (v bit == v (S.ith_bit (as_seq h0 k) (253 - v i)));
let sw = swap.(0ul) ^. bit in
logxor_lemma1 (LSeq.index (as_seq h0 swap) 0) bit;
cswap2 #s sw nq nq_p1;
point_add_and_double #s q p01_tmp1 tmp2;
swap.(0ul) <- bit
#pop-options
#push-options "--z3rlimit 300 --fuel 1 --ifuel 1"
val ladder_step_loop:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
v (LSeq.index (as_seq h0 bit) 0) <= 1 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let (p0, p1, b) =
Lib.LoopCombinators.repeati 251
(S.ladder_step (as_seq h0 k) (fget_xz h0 q))
(fget_xz h0 nq, fget_xz h0 nq_p1, LSeq.index (as_seq h0 bit) 0) in
p0 == fget_xz h1 nq /\ p1 == fget_xz h1 nq_p1 /\ b == LSeq.index (as_seq h1 bit) 0 /\
v (LSeq.index (as_seq h1 bit) 0) <= 1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1)))
[@ Meta.Attribute.inline_ ]
let ladder_step_loop #s k q p01_tmp1_swap tmp2 =
let h0 = ST.get () in
[@ inline_let]
let spec_fh h0 =
S.ladder_step (as_seq h0 k) (fget_x h0 q, fget_z h0 q) in
[@ inline_let]
let acc h : GTot (tuple3 S.proj_point S.proj_point uint64) =
let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
(fget_xz h nq, fget_xz h nq_p1, LSeq.index (as_seq h bit) 0) in
[@ inline_let]
let inv h (i:nat{i <= 251}) =
let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h /\
v (LSeq.index (as_seq h bit) 0) <= 1 /\
state_inv_t h (get_x q) /\ state_inv_t h (get_z q) /\
state_inv_t h (get_x nq) /\ state_inv_t h (get_z nq) /\
state_inv_t h (get_x nq_p1) /\ state_inv_t h (get_z nq_p1) /\
acc h == Lib.LoopCombinators.repeati i (spec_fh h0) (acc h0) in
Lib.Loops.for 0ul 251ul inv
(fun i ->
Lib.LoopCombinators.unfold_repeati 251 (spec_fh h0) (acc h0) (v i);
ladder_step #s k q i p01_tmp1_swap tmp2)
#pop-options
#push-options "--z3refresh --fuel 0 --ifuel 1 --z3rlimit 800"
val ladder0_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq ==
M.montgomery_ladder1_0 (as_seq h0 k) (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1)))
[@ Meta.Attribute.inline_ ]
let ladder0_ #s k q p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let nq : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 : point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let swap:lbuffer uint64 1ul = sub p01_tmp1_swap (8ul *! nlimb s) 1ul in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap (8ul *! nlimb s) 1ul == swap);
// bit 255 is 0 and bit 254 is 1
cswap2 #s (u64 1) nq nq_p1;
point_add_and_double #s q p01_tmp1 tmp2;
swap.(0ul) <- u64 1;
//Got about 1K speedup by removing 4 iterations here.
//First iteration can be skipped because top bit of scalar is 0
ladder_step_loop #s k q p01_tmp1_swap tmp2;
let sw = swap.(0ul) in
cswap2 #s sw nq nq_p1
val ladder1_:
#s:field_spec
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 p01_tmp1 /\ live h0 tmp2 /\ disjoint p01_tmp1 tmp2 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == M.montgomery_ladder1_1 (fget_xz h0 nq))) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.AddAndDouble.fst.checked",
"Hacl.Impl.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"Hacl.Impl.Curve25519.AddAndDouble.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Generic.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.AddAndDouble",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.AddAndDouble",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Finv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 800,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p01_tmp1:
Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s)
(8ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s) ->
tmp2: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Lib.Buffer.lbuffer",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"Hacl.Impl.Curve25519.AddAndDouble.point_double",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.Buffer.gsub",
"Lib.Buffer.buffer_t",
"Prims.l_or",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.Buffer.length",
"Lib.IntTypes.v",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.mul",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Hacl.Impl.Curve25519.AddAndDouble.point"
] | [] | false | true | false | false | false | let ladder1_ #s p01_tmp1 tmp2 =
| let nq:point s = sub p01_tmp1 0ul (2ul *! nlimb s) in
let tmp1 = sub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) in
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) == tmp1);
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2 | false |
Steel.ST.GenArraySwap.fst | Steel.ST.GenArraySwap.intro_array_swap_outer_invariant | val intro_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit
opened
(array_swap_outer_invariant_body0 pts_to pi i s)
(fun _ -> array_swap_outer_invariant pts_to n l bz s0 pi b)
(array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) b)
(fun _ -> True) | val intro_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit
opened
(array_swap_outer_invariant_body0 pts_to pi i s)
(fun _ -> array_swap_outer_invariant pts_to n l bz s0 pi b)
(array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) b)
(fun _ -> True) | let intro_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit opened
(array_swap_outer_invariant_body0 pts_to pi i s)
(fun _ -> array_swap_outer_invariant pts_to n l bz s0 pi b)
(array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) b)
(fun _ -> True)
= let w = {
i = i;
s = s;
}
in
rewrite (array_swap_outer_invariant_body0 pts_to pi i s) (array_swap_outer_invariant_body0 pts_to pi w.i w.s);
rewrite (array_swap_outer_invariant0 pts_to n l bz s0 pi b) (array_swap_outer_invariant pts_to n l bz s0 pi b) | {
"file_name": "lib/steel/Steel.ST.GenArraySwap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 112,
"end_line": 229,
"start_col": 0,
"start_line": 206
} | module Steel.ST.GenArraySwap
open Steel.ST.GenElim
module Prf = Steel.ST.GenArraySwap.Proof
module R = Steel.ST.Reference
let gcd_inv_prop
(n0: nat)
(l0: nat)
(n: nat)
(l: nat)
(b: bool)
: Tot prop
= l0 < n0 /\
l < n /\
(Prf.mk_bezout n0 l0).d == (Prf.mk_bezout n l).d /\
b == (l > 0)
[@@__reduce__]
let gcd_inv0
(n0: SZ.t)
(l0: SZ.t)
(pn: R.ref SZ.t)
(pl: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun n -> exists_ (fun l ->
R.pts_to pn full_perm n `star`
R.pts_to pl full_perm l `star`
pure (gcd_inv_prop (SZ.v n0) (SZ.v l0) (SZ.v n) (SZ.v l) b)
))
let gcd_inv
(n0: SZ.t)
(l0: SZ.t)
(pn: R.ref SZ.t)
(pl: R.ref SZ.t)
(b: bool)
: Tot vprop
= gcd_inv0 n0 l0 pn pl b
let gcd_post
(n0: SZ.t)
(l0: SZ.t)
(res: SZ.t)
: Tot prop
= SZ.v l0 < SZ.v n0 /\
SZ.v res == (Prf.mk_bezout (SZ.v n0) (SZ.v l0)).d
#push-options "--z3rlimit 16"
#restart-solver
let gcd
(n0: SZ.t)
(l0: SZ.t)
: ST SZ.t
emp
(fun _ -> emp)
(SZ.v l0 < SZ.v n0)
(fun res -> gcd_post n0 l0 res)
= let res =
R.with_local n0 (fun pn ->
R.with_local l0 (fun pl ->
noop ();
rewrite (gcd_inv0 n0 l0 pn pl (l0 `SZ.gt` 0sz)) (gcd_inv n0 l0 pn pl (l0 `SZ.gt` 0sz));
Steel.ST.Loops.while_loop
(gcd_inv n0 l0 pn pl)
(fun _ ->
let gb = elim_exists () in
rewrite (gcd_inv n0 l0 pn pl gb) (gcd_inv0 n0 l0 pn pl gb);
let _ = gen_elim () in
let l = R.read pl in
[@@inline_let]
let b = l `SZ.gt` 0sz in
noop ();
rewrite (gcd_inv0 n0 l0 pn pl b) (gcd_inv n0 l0 pn pl b);
return b
)
(fun _ ->
rewrite (gcd_inv n0 l0 pn pl true) (gcd_inv0 n0 l0 pn pl true);
let _ = gen_elim () in
let n = R.read pn in
let l = R.read pl in
[@@inline_let]
let l' = SZ.rem n l in
R.write pn l;
R.write pl l';
rewrite (gcd_inv0 n0 l0 pn pl (l' `SZ.gt` 0sz)) (gcd_inv n0 l0 pn pl (l' `SZ.gt` 0sz));
noop ()
);
rewrite (gcd_inv n0 l0 pn pl false) (gcd_inv0 n0 l0 pn pl false);
let _ = gen_elim () in
let res = R.read pn in
return res
)
)
in
elim_pure (gcd_post n0 l0 res);
return res
#pop-options
let array_swap_partial_invariant
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
: GTot prop
= n == Seq.length s0 /\
n == Seq.length s /\
0 < l /\
l < n /\
i <= bz.d /\
(forall (i': Prf.nat_up_to bz.d) .
(forall (j: Prf.nat_up_to bz.q_n) .
(i' < i) ==> (
let idx = Prf.iter_fun #(Prf.nat_up_to n) (Prf.jump n l) j i' in
Seq.index s idx == Seq.index s0 (Prf.jump n l idx)
))) /\
(forall (i': Prf.nat_up_to bz.d) .
(forall (j: Prf.nat_up_to bz.q_n) .
(i' > i) ==> (
let idx = Prf.iter_fun #(Prf.nat_up_to n) (Prf.jump n l) j i' in
Seq.index s idx == Seq.index s0 idx
)))
let array_swap_inner_invariant_prop
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
(j: nat)
(idx: nat)
(b: bool)
: GTot prop
= Prf.array_swap_inner_invariant s0 n l bz s i j idx /\
(b == (j < bz.q_n - 1))
let array_swap_outer_invariant_prop
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
(b: bool)
: GTot prop
= Prf.array_swap_outer_invariant s0 n l bz s i /\
(b == (i < bz.d))
[@@__reduce__]
let array_swap_outer_invariant_body0
(#t: Type)
(pts_to: array_pts_to_t t)
(pi: R.ref SZ.t)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: Tot vprop
=
R.pts_to pi full_perm i `star`
pts_to s
[@@erasable]
noeq
type array_swap_outer_invariant_t (t: Type)
= {
i: SZ.t;
s: Ghost.erased (Seq.seq t);
}
[@@__reduce__]
let array_swap_outer_invariant0
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun w ->
array_swap_outer_invariant_body0 pts_to pi w.i w.s `star`
pure (array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v w.i) b)
)
let array_swap_outer_invariant
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: Tot vprop
= array_swap_outer_invariant0 pts_to n l bz s0 pi b | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"Steel.ST.GenArraySwap.Proof.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenArraySwap.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.ST.GenArraySwap.Proof",
"short_module": "Prf"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pts_to: Steel.ST.GenArraySwap.array_pts_to_t t ->
n: FStar.SizeT.t ->
l: FStar.SizeT.t ->
bz: Steel.ST.GenArraySwap.Proof.bezout (FStar.SizeT.v n) (FStar.SizeT.v l) ->
s0: FStar.Ghost.erased (FStar.Seq.Base.seq t) ->
pi: Steel.ST.Reference.ref FStar.SizeT.t ->
b: Prims.bool ->
i: FStar.SizeT.t ->
s: FStar.Ghost.erased (FStar.Seq.Base.seq t)
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.ST.GenArraySwap.array_pts_to_t",
"FStar.SizeT.t",
"Steel.ST.GenArraySwap.Proof.bezout",
"FStar.SizeT.v",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Reference.ref",
"Prims.bool",
"Steel.ST.Util.rewrite",
"Steel.ST.GenArraySwap.array_swap_outer_invariant0",
"Steel.ST.GenArraySwap.array_swap_outer_invariant",
"Prims.unit",
"Steel.ST.GenArraySwap.array_swap_outer_invariant_body0",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_outer_invariant_t__item__i",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_outer_invariant_t__item__s",
"Steel.ST.GenArraySwap.array_swap_outer_invariant_t",
"Steel.ST.GenArraySwap.Mkarray_swap_outer_invariant_t",
"Steel.Effect.Common.vprop",
"Steel.ST.GenArraySwap.array_swap_outer_invariant_prop",
"Prims.l_True"
] | [] | false | true | false | false | false | let intro_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit
opened
(array_swap_outer_invariant_body0 pts_to pi i s)
(fun _ -> array_swap_outer_invariant pts_to n l bz s0 pi b)
(array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) b)
(fun _ -> True) =
| let w = { i = i; s = s } in
rewrite (array_swap_outer_invariant_body0 pts_to pi i s)
(array_swap_outer_invariant_body0 pts_to pi w.i w.s);
rewrite (array_swap_outer_invariant0 pts_to n l bz s0 pi b)
(array_swap_outer_invariant pts_to n l bz s0 pi b) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_loc_includes | 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')) | 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 = M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 243,
"start_col": 0,
"start_line": 243
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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') | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let modifies_loc_includes s1 h h' s2 =
| M.modifies_loc_includes s1 (_ih h).hs (_ih h').hs s2 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.buffer_read | 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
)) | 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 =
if i < 0 || i >= buffer_length b then default_of_typ t else
Seq.index (buffer_as_seq h b) i | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 264,
"start_col": 0,
"start_line": 262
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | Prims.Ghost | [] | [] | [
"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"
] | [] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_goal_directed_trans | 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)] | 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 =
modifies_trans s12 h1 h2 s13 h3;
modifies_loc_includes s13 h1 h3 (loc_union s12 s13);
() | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 249,
"start_col": 0,
"start_line": 246
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)] | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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);
() | false |
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_goal_directed_trans2 | 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)] | 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 = modifies_goal_directed_trans s12 h1 h2 s13 h3 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 251,
"start_col": 0,
"start_line": 251
} | 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);
() | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.loc",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.modifies_goal_directed_trans",
"Prims.unit"
] | [] | true | false | true | false | false | let modifies_goal_directed_trans2 s12 h1 h2 s13 h3 =
| modifies_goal_directed_trans s12 h1 h2 s13 h3 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.index128_get_heap_val128_aux | 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)) | 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)) =
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 () | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 163,
"start_col": 0,
"start_line": 153
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 () | false |
Vale.AsLowStar.Wrapper.fst | Vale.AsLowStar.Wrapper.vale_lemma_as_prediction | val vale_lemma_as_prediction
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(#regs_modified:MS.reg_64 -> bool)
(#xmms_modified:MS.reg_xmm -> bool)
(code:V.va_code)
(args:IX64.arg_list)
(pre:VSig.vale_pre_tl [])
(post:VSig.vale_post_tl [])
(v:VSig.vale_sig_tl regs_modified xmms_modified args (coerce code) pre post)
: IX64.prediction
max_arity
arg_reg
regs_modified
xmms_modified
(coerce code)
args
(prediction_pre_rel #max_arity #arg_reg pre (coerce code) args)
(prediction_post_rel #max_arity post (coerce code) args) | val vale_lemma_as_prediction
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(#regs_modified:MS.reg_64 -> bool)
(#xmms_modified:MS.reg_xmm -> bool)
(code:V.va_code)
(args:IX64.arg_list)
(pre:VSig.vale_pre_tl [])
(post:VSig.vale_post_tl [])
(v:VSig.vale_sig_tl regs_modified xmms_modified args (coerce code) pre post)
: IX64.prediction
max_arity
arg_reg
regs_modified
xmms_modified
(coerce code)
args
(prediction_pre_rel #max_arity #arg_reg pre (coerce code) args)
(prediction_post_rel #max_arity post (coerce code) args) | let vale_lemma_as_prediction
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(#regs_modified:MS.reg_64 -> bool)
(#xmms_modified:MS.reg_xmm -> bool)
(code:V.va_code)
(args:IX64.arg_list)
(pre:VSig.vale_pre_tl [])
(post:VSig.vale_post_tl [])
(v:VSig.vale_sig_tl regs_modified xmms_modified args (coerce code) pre post)
= fun h0 s0 ->
let c_code : BS.code = coerce code in
let va_s0 = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
core_create_lemma #max_arity #arg_reg args h0;
assert (SL.state_to_S va_s0 == s0);
assert (LSig.mem_correspondence args h0 va_s0);
assert (va_s0.VS.vs_ok);
assert (LSig.vale_pre_hyp #max_arity #arg_reg args va_s0);
assert (elim_nil pre va_s0);
let (va_s1, f) = VSig.elim_vale_sig_nil v va_s0 in
assert (V.eval_code code va_s0 f va_s1);
eval_code_rel (c_code) va_s0 va_s1 f;
let Some s1 = BS.machine_eval_code (c_code) (coerce f) s0 in
assert (VL.state_eq_opt true (Some (SL.state_to_S va_s1)) (Some s1));
assert (VSig.vale_calling_conventions va_s0 va_s1 regs_modified xmms_modified);
assert (IX64.calling_conventions s0 s1 regs_modified xmms_modified);
assert (ME.modifies (VSig.mloc_modified_args args) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1));
let final_mem = va_s1.VS.vs_heap in
let h1 = hs_of_mem (as_mem final_mem.vf_heap) in
Vale.AsLowStar.MemoryHelpers.relate_modifies args va_s0.VS.vs_heap va_s1.VS.vs_heap;
assert (B.modifies (loc_modified_args args) h0 h1);
Vale.AsLowStar.MemoryHelpers.modifies_equal_domains
(VSig.mloc_modified_args args) va_s0.VS.vs_heap final_mem;
Vale.AsLowStar.MemoryHelpers.modifies_same_roots
(VSig.mloc_modified_args args) va_s0.VS.vs_heap final_mem;
Vale.AsLowStar.MemoryHelpers.state_eq_down_mem va_s1 s1;
assert (heap_create_machine (as_mem final_mem.vf_heap) == heap_get s1.BS.ms_heap);
mem_correspondence_refl args va_s1;
assert (VSig.readable args (ME.get_vale_heap va_s1.VS.vs_heap));
assert (disjoint_or_eq args);
readable_all_live va_s1.VS.vs_heap.vf_heap args;
assert (all_live h1 args);
assert (mem_roots_p h1 args);
assert (B.modifies (loc_modified_args args) h0 h1);
assert (LSig.(to_low_post post args h0 (IX64.return_val s1) h1));
(IX64.return_val s1, coerce f, as_mem va_s1.VS.vs_heap.vf_heap) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Wrapper.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 585,
"start_col": 0,
"start_line": 540
} | module Vale.AsLowStar.Wrapper
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module I = Vale.Interop
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module SL = Vale.X64.StateLemmas
module VL = Vale.X64.Lemmas
module ST = FStar.HyperStack.ST
open FStar.Mul
open FStar.Calc
//let lemma_create_initial_vale_state_core
// (#max_arity:nat)
// (#reg_arg:IX64.arg_reg_relation max_arity)
// (args:IX64.arg_list)
// (h0:HS.mem{mem_roots_p h0 args})
// : Lemma
// (ensures (
// let s = LSig.create_initial_vale_state #max_arity #reg_arg args h0 in
// hs_of_mem (as_mem s.VS.vs_heap.vf_heap) == h0
// ))
// = ()
#reset-options "--initial_ifuel 2 --max_ifuel 2"
let rec core_create_lemma_disjointness
(args:list arg{disjoint_or_eq args})
: Lemma
(ensures VSig.disjoint_or_eq args)
= match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
BigOps.pairwise_and'_cons VSig.disjoint_or_eq_1 hd tl;
core_create_lemma_disjointness tl;
assert (VSig.disjoint_or_eq tl);
let rec aux (n:list arg)
: Lemma (requires (BigOps.big_and' (disjoint_or_eq_1 hd) n))
(ensures (BigOps.big_and' (VSig.disjoint_or_eq_1 hd) n)) =
match n with
| [] -> ()
| n::ns ->
BigOps.big_and'_cons (disjoint_or_eq_1 hd) n ns;
BigOps.big_and'_cons (VSig.disjoint_or_eq_1 hd) n ns;
aux ns
in
aux tl
#reset-options
#push-options "--z3rlimit 40 --fuel 1 --ifuel 2"
let rec args_b8_lemma (args:list arg) (x:arg)
: Lemma
(List.memP x args ==>
(match x with
| (| TD_Buffer src bt _, x |) -> List.memP (mut_to_b8 src x) (args_b8 args)
| (| TD_ImmBuffer src bt _, x |) -> List.memP (imm_to_b8 src x) (args_b8 args)
| _ -> True))
= match args with
| [] -> ()
| a::q ->
assert (List.memP x q ==> List.memP x args);
args_b8_lemma q x
#pop-options
let readable_cons (hd:arg) (tl:list arg) (s:ME.vale_heap)
: Lemma VSig.(readable (hd::tl) s <==> (readable_one s hd /\ readable tl s))
= BigOps.big_and'_cons VSig.(readable_one s) hd tl
let arg_is_registered_root (h:ME.vale_heap) (a:arg) =
match a with
| (| TD_Buffer src bt _, x |) ->
List.memP (mut_to_b8 src x) (ptrs_of_mem (as_mem h))
| (| TD_ImmBuffer src bt _, x |) ->
List.memP (imm_to_b8 src x) (ptrs_of_mem (as_mem h))
| _ -> true
#set-options "--z3rlimit 20"
let core_create_lemma_readable
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures
(let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
VSig.readable args (ME.get_vale_heap va_s.VS.vs_heap)))
=
let readable_registered_one (a:arg) (h:ME.vale_heap)
: Lemma VSig.(arg_is_registered_root h a <==> readable_one h a)
= match a with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.reveal_readable #src #bt x h;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal src bt x
| (| TD_ImmBuffer src bt ig, x |) ->
Vale.AsLowStar.MemoryHelpers.reveal_imm_readable #src #bt x h;
assert_norm (ME.buffer_readable h (as_vale_immbuffer #src #bt x) <==>
VSig.readable_one h (| TD_ImmBuffer src bt ig, x |))
| (| TD_Base _, _ |) -> ()
in
let rec readable_registered_all
(args:list arg)
(h:ME.vale_heap {forall x. List.memP x args ==> arg_is_registered_root h x})
: Lemma VSig.(readable args h)
= match args with
| [] -> ()
| hd::tl ->
readable_cons hd tl h;
readable_registered_one hd h;
readable_registered_all tl h
in
let readable_mk_mem
(args:list arg)
(h:mem_roots args)
: Lemma
(let mem = mk_mem args h in
VSig.readable args (create_initial_vale_heap mem))
= let mem = mk_mem args h in
FStar.Classical.forall_intro (FStar.Classical.move_requires (args_b8_lemma args));
readable_registered_all args (create_initial_vale_heap mem)
in
readable_mk_mem args h0
let readable_live_one (h:ME.vale_heap) (a:arg)
: Lemma (VSig.readable_one h a ==>
live_arg (hs_of_mem (as_mem h)) a)
= match a with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.readable_live #src #bt x h
| (| TD_ImmBuffer src bt ig, x |) ->
Vale.AsLowStar.MemoryHelpers.readable_imm_live #src #bt x h;
assert_norm (ME.buffer_readable h (as_vale_immbuffer #src #bt x) <==>
VSig.readable_one h (| TD_ImmBuffer src bt ig, x |))
| (| TD_Base _, _ |) -> ()
let rec readable_all_live (h:ME.vale_heap) (args:list arg)
: Lemma (VSig.readable args h ==>
all_live (hs_of_mem (as_mem h)) args)
= match args with
| [] -> ()
| hd::tl ->
readable_cons hd tl h;
all_live_cons hd tl (hs_of_mem (as_mem h));
readable_live_one h hd;
readable_all_live h tl
let core_create_lemma_mem_correspondance
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures
(let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.mem_correspondence args h0 va_s))
=
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let rec aux (accu:list arg) : Lemma
(requires (forall x. List.memP x accu ==> (live_arg h0 x)))
(ensures LSig.mem_correspondence accu h0 va_s) =
match accu with
| [] -> ()
| hd::tl -> aux tl;
match hd with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.buffer_as_seq_reveal src bt x args h0;
let db = get_downview x in
DV.length_eq db;
let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in
assert (Seq.equal (UV.as_seq h0 ub) (UV.as_seq h0 ub))
| (| TD_ImmBuffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.immbuffer_as_seq_reveal src bt x args h0;
let db = get_downview x in
DV.length_eq db;
let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in
assert (Seq.equal (UV.as_seq h0 ub) (UV.as_seq h0 ub))
| (| TD_Base _, _ |) -> ()
in
BigOps.big_and'_forall (live_arg h0) args;
aux args
let rec register_args'
(max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.length args = n})
(regs:IX64.registers)
: prop
= match args with
| [] -> True
| hd::tl ->
register_args' max_arity arg_reg (n - 1) tl regs /\
(if n > max_arity then True
else regs (arg_reg.IX64.of_arg (n - 1)) == IX64.arg_as_nat64 hd)
let rec lemma_register_args'_aux
(max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.length args = n})
(regs1 regs2:IX64.registers)
: Lemma
(requires
register_args' max_arity arg_reg n args regs1 /\
(forall r. (forall (i:IX64.reg_nat max_arity{i >= n}). r <> (arg_reg.IX64.of_arg i)) /\
r <> MS.rRsp ==>
regs1 r == regs2 r))
(ensures register_args' max_arity arg_reg n args regs2)
= match args with
| [] -> ()
| hd::tl ->
lemma_register_args'_aux max_arity arg_reg (n-1) tl regs1 regs2
let rec lemma_register_args'
(max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(regs:IX64.registers)
: Lemma
(ensures
(let final_regs = IX64.register_of_args max_arity arg_reg (List.length args) args regs in
register_args' max_arity arg_reg (List.length args) args final_regs))
= let final_regs = IX64.register_of_args max_arity arg_reg (List.length args) args regs in
match args with
| [] -> ()
| hd::tl ->
let n = List.length args in
let regs' = (IX64.register_of_args max_arity arg_reg (n-1) tl regs) in
lemma_register_args' max_arity arg_reg tl regs;
lemma_register_args'_aux max_arity arg_reg (n-1) tl regs' final_regs
let core_create_lemma_register_args
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.register_args max_arity arg_reg (List.length args) args va_s))
=
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let regs' = IX64.register_of_args max_arity arg_reg (List.Tot.length args) args IA.init_regs in
lemma_register_args' max_arity arg_reg args IA.init_regs;
let open MS in
let regs = FunctionalExtensionality.on reg_64 regs' in
lemma_register_args'_aux max_arity arg_reg (List.length args) args regs' regs;
assert (register_args' max_arity arg_reg (List.length args) args regs);
let rec aux
(args:IX64.arg_list)
(s:VS.vale_state)
(args':list arg)
(h0:HS.mem{mem_roots_p h0 args'})
: Lemma
(requires
(forall r. VS.eval_reg_64 r s == regs r) /\
register_args' max_arity arg_reg (List.length args) args regs /\
s.VS.vs_heap.vf_heap == create_initial_vale_heap (mk_mem args' h0))
(ensures LSig.register_args max_arity arg_reg (List.length args) args s)
(decreases args)
= let n = List.length args in
match args with
| [] -> ()
| hd::tl -> aux tl s args' h0;
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ -> Vale.AsLowStar.MemoryHelpers.buffer_addr_reveal src bt x args' h0
| TD_ImmBuffer src bt _ -> Vale.AsLowStar.MemoryHelpers.immbuffer_addr_reveal src bt x args' h0
| TD_Base _ -> ()
in
aux args va_s args h0
let core_create_lemma_state
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures
(let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
fst (IX64.create_initial_trusted_state max_arity arg_reg args h0) == SL.state_to_S va_s))
= let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let tr_s = fst (IX64.create_initial_trusted_state max_arity arg_reg args h0) in
let sl_s = SL.state_to_S va_s in
assert (tr_s.BS.ms_stackTaint == va_s.VS.vs_stackTaint);
//SL.lemma_to_ok va_s;
let aux_flag (f:MS.flag) : Lemma (tr_s.BS.ms_flags f == sl_s.BS.ms_flags f)
= ()//SL.lemma_to_flags va_s f
in
Classical.forall_intro aux_flag;
assert (FunctionalExtensionality.feq tr_s.BS.ms_flags sl_s.BS.ms_flags);
//SL.lemma_to_mem va_s;
//SL.lemma_to_stack va_s;
let aux_reg (r:MS.reg) : Lemma (tr_s.BS.ms_regs r == sl_s.BS.ms_regs r)
= ()//SL.lemma_to_reg va_s r
in
Classical.forall_intro aux_reg;
assert (FunctionalExtensionality.feq tr_s.BS.ms_regs sl_s.BS.ms_regs);
// Vale.AsLowStar.MemoryHelpers.get_heap_mk_mem_reveal args h0;
Vale.AsLowStar.MemoryHelpers.mk_stack_reveal tr_s.BS.ms_stack
let rec stack_args' (max_arity:nat)
(n:nat)
(args:list arg{List.Tot.length args = n})
(rsp:int)
(stack:Map.t int Vale.Def.Words_s.nat8)
: prop =
match args with
| [] -> True
| hd::tl ->
stack_args' max_arity (n-1) tl rsp stack /\
(if n <= max_arity then True // This arg is passed in registers
else
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ rsp
in
BS.valid_addr64 ptr stack /\
BS.get_heap_val64 ptr stack == IX64.arg_as_nat64 hd)
let frame_update_get_heap (ptr:int) (v:MS.nat64) (mem:BS.machine_heap) (j:int) : Lemma
(requires ptr >= j + 8)
(ensures BS.get_heap_val64 j mem == BS.get_heap_val64 j (BS.update_heap64 ptr v mem))
=
BS.get_heap_val64_reveal ();
BS.update_heap64_reveal ()
let frame_update_valid_heap (ptr:int) (v:MS.nat64) (mem:BS.machine_heap) (j:int) : Lemma
(requires ptr >= j + 8)
(ensures BS.valid_addr64 j mem == BS.valid_addr64 j (BS.update_heap64 ptr v mem))
=
reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
BS.update_heap64_reveal ()
let rec stack_of_args_stack_args'_aux
(max_arity:nat)
(n_init:nat)
(n:nat)
(args:IX64.arg_list{List.Tot.length args = n})
(rsp:int)
(stack:Map.t int Vale.Def.Words_s.nat8)
(v:MS.nat64)
: Lemma
(requires stack_args' max_arity n args rsp stack /\ n_init >= n)
(ensures
(let ptr = (n_init - max_arity) * 8 + (if IA.win then 32 else 0) + 8 + rsp in
stack_args' max_arity n args rsp (BS.update_heap64 ptr v stack)))
= match args with
| [] -> ()
| hd::tl ->
stack_of_args_stack_args'_aux max_arity n_init (n-1) tl rsp stack v;
if n <= max_arity then ()
else (
let fixed = (n_init - max_arity) * 8 + (if IA.win then 32 else 0) + 8 + rsp in
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ rsp
in
calc ( <= ) {
((n - max_arity) - 1) * 8;
( <= ) { FStar.Math.Lemmas.lemma_mult_le_right 8 ((n - max_arity) - 1) (n_init - max_arity) }
(n_init - max_arity) * 8;
};
frame_update_get_heap fixed v stack ptr;
frame_update_valid_heap fixed v stack ptr
)
#push-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 150 --z3refresh"
let stack_of_args_stack_args'
(max_arity:nat)
(n:nat)
(args:IX64.arg_list{List.Tot.length args = n})
(init_rsp:MS.nat64{init_rsp >= 4096}) : Lemma
(let mem = Map.const_on Set.empty 0 in
stack_args' max_arity n args init_rsp (IX64.stack_of_args max_arity n init_rsp args mem))
=
reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
reveal_opaque (`%BS.valid_addr128) BS.valid_addr128;
let rec aux (args:IX64.arg_list) (accu:Map.t int Vale.Def.Words_s.nat8) : Lemma (ensures (
stack_args' max_arity (List.length args) args init_rsp
(IX64.stack_of_args max_arity (List.length args) init_rsp args accu)))
(decreases (List.length args))
=
reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
reveal_opaque (`%BS.valid_addr128) BS.valid_addr128;
match args with
| [] -> ()
| hd::tl ->
aux tl accu;
let n = List.length args in
if n <= max_arity then ()
else (
let ptr = ((n - max_arity) - 1) * 8 // Arguments on the stack are pushed from right to left
+ (if IA.win then 32 else 0) // The shadow space on Windows comes next
+ 8 // The return address is then pushed on the stack
+ init_rsp // And we then have all the extra slots required for the Vale procedure
in
let accu' = IX64.stack_of_args max_arity (n-1) init_rsp tl accu in
let v = IX64.arg_as_nat64 hd in // We will store the arg hd
let h_final = BS.update_heap64 ptr v accu' in
stack_of_args_stack_args'_aux max_arity (n-1) (n-1) tl init_rsp accu' v;
Vale.Arch.MachineHeap.correct_update_get64 ptr v accu';
BS.update_heap64_reveal ()
)
in aux args (Map.const_on Set.empty 0)
#pop-options
#reset-options "--z3rlimit 40"
let core_create_lemma_stack_args
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.stack_args max_arity (List.length args) args va_s))
= let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let init_rsp = IA.init_regs MS.rRsp in
let stack = Map.const_on Set.empty 0 in
let stack_map = IX64.stack_of_args max_arity (List.Tot.length args) init_rsp args stack in
let stack_f = BS.Machine_stack init_rsp stack_map in
let rec aux (accu:IX64.arg_list{List.length accu <= List.length args}) : Lemma
(requires
stack_args' max_arity (List.length accu) accu init_rsp stack_map)
(ensures LSig.stack_args max_arity (List.length accu) accu va_s)
(decreases (List.length accu))
=
match accu with
| [] -> ()
| hd::tl ->
aux tl;
let i = List.length accu in
if i <= max_arity then ()
else (
let ptr =
((i - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ init_rsp
in
Vale.AsLowStar.MemoryHelpers.mk_stack_reveal stack_f;
SI.lemma_valid_taint_stack64_reveal ptr MS.Public va_s.VS.vs_stackTaint;
let aux2 () : Lemma (IX64.arg_as_nat64 hd == LSig.arg_as_nat64 hd va_s) =
match hd with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.buffer_addr_reveal src bt x args h0
| (| TD_ImmBuffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.immbuffer_addr_reveal src bt x args h0
| _ -> ()
in aux2()
)
in
stack_of_args_stack_args' max_arity (List.length args) args init_rsp;
aux args
let core_create_lemma
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures
(let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
fst (IX64.create_initial_trusted_state max_arity arg_reg args h0) == SL.state_to_S va_s /\
LSig.mem_correspondence args h0 va_s /\
VSig.disjoint_or_eq args /\
VSig.readable args (ME.get_vale_heap va_s.VS.vs_heap) /\
LSig.vale_pre_hyp #max_arity #arg_reg args va_s /\
ST.equal_domains h0 (hs_of_mem (as_mem va_s.VS.vs_heap.vf_heap))
))
= let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let t_state = fst (IX64.create_initial_trusted_state max_arity arg_reg args h0) in
let t_stack = t_state.BS.ms_stack in
core_create_lemma_mem_correspondance #max_arity #arg_reg args h0;
core_create_lemma_disjointness args;
core_create_lemma_readable #max_arity #arg_reg args h0;
core_create_lemma_register_args #max_arity #arg_reg args h0;
core_create_lemma_stack_args #max_arity #arg_reg args h0;
Vale.AsLowStar.MemoryHelpers.mk_stack_reveal t_stack;
Vale.AsLowStar.MemoryHelpers.core_create_lemma_taint_hyp #max_arity #arg_reg args h0;
core_create_lemma_state #max_arity #arg_reg args h0
let eval_code_ts (c:BS.code)
(s0:BS.machine_state)
(f0:nat)
(s1:BS.machine_state) : Type0 =
VL.state_eq_opt true (BS.machine_eval_code c f0 s0) (Some s1)
let eval_code_rel (c:BS.code)
(va_s0 va_s1:V.va_state) (f:V.va_fuel)
: Lemma
(requires (V.eval_code c va_s0 f va_s1))
(ensures (eval_code_ts c (SL.state_to_S va_s0) (coerce f) (SL.state_to_S va_s1)))
= Vale.AsLowStar.MemoryHelpers.decls_eval_code_reveal c va_s0 va_s1 f
let rec mem_correspondence_refl (args:list arg)
(va_s:V.va_state)
: Lemma
(ensures LSig.mem_correspondence args (hs_of_mem (as_mem va_s.VS.vs_heap.vf_heap)) va_s)
=
let h = hs_of_mem (as_mem va_s.VS.vs_heap.vf_heap) in
match args with
| [] -> ()
| hd::tl ->
mem_correspondence_refl tl va_s;
match hd with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.buffer_as_seq_reveal2 src bt x va_s
| (| TD_ImmBuffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.immbuffer_as_seq_reveal2 src bt x va_s
| _ -> ()
////////////////////////////////////////////////////////////////////////////////
let loc_includes_union (l1 l1' l:B.loc)
: Lemma (requires B.(loc_includes l1 l1'))
(ensures B.(loc_includes (loc_union l1 l) (loc_union l1' l)))
= let open B in
loc_includes_union_l l1 l l1';
loc_includes_union_l l1 l l;
loc_includes_union_r (loc_union l1 l) l1' l | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Lemmas.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.Wrapper.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 40,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Decls.va_code ->
args: Vale.Interop.X64.arg_list ->
pre: Vale.AsLowStar.ValeSig.vale_pre_tl [] ->
post: Vale.AsLowStar.ValeSig.vale_post_tl [] ->
v:
Vale.AsLowStar.ValeSig.vale_sig_tl regs_modified
xmms_modified
args
(Vale.Interop.Base.coerce code)
pre
post
-> Vale.Interop.X64.prediction max_arity
arg_reg
regs_modified
xmms_modified
(Vale.Interop.Base.coerce code)
args
(Vale.AsLowStar.Wrapper.prediction_pre_rel pre (Vale.Interop.Base.coerce code) args)
(Vale.AsLowStar.Wrapper.prediction_post_rel post (Vale.Interop.Base.coerce code) args) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Interop.X64.arg_reg_relation",
"Vale.X64.Machine_s.reg_64",
"Prims.bool",
"Vale.X64.Machine_s.reg_xmm",
"Vale.X64.Decls.va_code",
"Vale.Interop.X64.arg_list",
"Vale.AsLowStar.ValeSig.vale_pre_tl",
"Prims.Nil",
"Vale.Interop.Base.td",
"Vale.AsLowStar.ValeSig.vale_post_tl",
"Vale.AsLowStar.ValeSig.vale_sig_tl",
"Vale.Interop.Base.coerce",
"Vale.Interop.Base.mem_roots",
"Vale.AsLowStar.Wrapper.prediction_pre_rel",
"Vale.X64.Machine_s.precode",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"FStar.Pervasives.Native.Mktuple3",
"FStar.UInt64.t",
"Vale.Interop.Heap_s.interop_heap",
"Vale.Interop.X64.return_val",
"Vale.X64.MemoryAdapters.as_mem",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Prims.unit",
"Prims._assert",
"Vale.AsLowStar.LowStarSig.to_low_post",
"LowStar.Monotonic.Buffer.modifies",
"Vale.Interop.Base.loc_modified_args",
"Vale.Interop.Base.mem_roots_p",
"Vale.Interop.Base.all_live",
"Vale.AsLowStar.Wrapper.readable_all_live",
"Vale.Interop.Base.disjoint_or_eq",
"Vale.AsLowStar.ValeSig.readable",
"Vale.X64.Memory.get_vale_heap",
"Vale.AsLowStar.Wrapper.mem_correspondence_refl",
"Prims.eq2",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.Heap.heap_create_machine",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.AsLowStar.MemoryHelpers.state_eq_down_mem",
"Vale.AsLowStar.MemoryHelpers.modifies_same_roots",
"Vale.AsLowStar.ValeSig.mloc_modified_args",
"Vale.AsLowStar.MemoryHelpers.modifies_equal_domains",
"Vale.AsLowStar.MemoryHelpers.relate_modifies",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Heap_s.hs_of_mem",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.X64.Memory.modifies",
"Vale.X64.State.vs_get_vale_heap",
"Vale.Interop.X64.calling_conventions",
"Vale.AsLowStar.ValeSig.vale_calling_conventions",
"Vale.X64.Lemmas.state_eq_opt",
"FStar.Pervasives.Native.Some",
"Vale.X64.StateLemmas.state_to_S",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code",
"Vale.AsLowStar.Wrapper.eval_code_rel",
"Vale.X64.Decls.eval_code",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.State.vale_state",
"Vale.AsLowStar.ValeSig.elim_vale_sig_nil",
"Vale.Interop.Base.elim_nil",
"Prims.prop",
"Vale.AsLowStar.LowStarSig.vale_pre_hyp",
"Prims.b2t",
"Vale.X64.State.__proj__Mkvale_state__item__vs_ok",
"Vale.AsLowStar.LowStarSig.mem_correspondence",
"Vale.AsLowStar.Wrapper.core_create_lemma",
"Vale.X64.Decls.vale_state_with_inv",
"Vale.AsLowStar.LowStarSig.create_initial_vale_state",
"Vale.X64.Machine_Semantics_s.code"
] | [] | false | false | false | false | false | let vale_lemma_as_prediction
(#max_arity: nat)
(#arg_reg: IX64.arg_reg_relation max_arity)
(#regs_modified: (MS.reg_64 -> bool))
(#xmms_modified: (MS.reg_xmm -> bool))
(code: V.va_code)
(args: IX64.arg_list)
(pre: VSig.vale_pre_tl [])
(post: VSig.vale_post_tl [])
(v: VSig.vale_sig_tl regs_modified xmms_modified args (coerce code) pre post)
=
| fun h0 s0 ->
let c_code:BS.code = coerce code in
let va_s0 = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
core_create_lemma #max_arity #arg_reg args h0;
assert (SL.state_to_S va_s0 == s0);
assert (LSig.mem_correspondence args h0 va_s0);
assert (va_s0.VS.vs_ok);
assert (LSig.vale_pre_hyp #max_arity #arg_reg args va_s0);
assert (elim_nil pre va_s0);
let va_s1, f = VSig.elim_vale_sig_nil v va_s0 in
assert (V.eval_code code va_s0 f va_s1);
eval_code_rel (c_code) va_s0 va_s1 f;
let Some s1 = BS.machine_eval_code (c_code) (coerce f) s0 in
assert (VL.state_eq_opt true (Some (SL.state_to_S va_s1)) (Some s1));
assert (VSig.vale_calling_conventions va_s0 va_s1 regs_modified xmms_modified);
assert (IX64.calling_conventions s0 s1 regs_modified xmms_modified);
assert (ME.modifies (VSig.mloc_modified_args args)
(VS.vs_get_vale_heap va_s0)
(VS.vs_get_vale_heap va_s1));
let final_mem = va_s1.VS.vs_heap in
let h1 = hs_of_mem (as_mem final_mem.vf_heap) in
Vale.AsLowStar.MemoryHelpers.relate_modifies args va_s0.VS.vs_heap va_s1.VS.vs_heap;
assert (B.modifies (loc_modified_args args) h0 h1);
Vale.AsLowStar.MemoryHelpers.modifies_equal_domains (VSig.mloc_modified_args args)
va_s0.VS.vs_heap
final_mem;
Vale.AsLowStar.MemoryHelpers.modifies_same_roots (VSig.mloc_modified_args args)
va_s0.VS.vs_heap
final_mem;
Vale.AsLowStar.MemoryHelpers.state_eq_down_mem va_s1 s1;
assert (heap_create_machine (as_mem final_mem.vf_heap) == heap_get s1.BS.ms_heap);
mem_correspondence_refl args va_s1;
assert (VSig.readable args (ME.get_vale_heap va_s1.VS.vs_heap));
assert (disjoint_or_eq args);
readable_all_live va_s1.VS.vs_heap.vf_heap args;
assert (all_live h1 args);
assert (mem_roots_p h1 args);
assert (B.modifies (loc_modified_args args) h0 h1);
assert (let open LSig in to_low_post post args h0 (IX64.return_val s1) h1);
(IX64.return_val s1, coerce f, as_mem va_s1.VS.vs_heap.vf_heap) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.writeable_mem64 | val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool | val writeable_mem64 (ptr:int) (h:vale_heap) : GTot bool | let writeable_mem64 ptr h = writeable_mem (TUInt64) ptr h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 410,
"start_col": 0,
"start_line": 410
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.writeable_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.bool"
] | [] | false | false | false | false | false | let writeable_mem64 ptr h =
| writeable_mem (TUInt64) ptr h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.seq_upd | 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)) | 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))
=
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 291,
"start_col": 0,
"start_line": 266
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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
(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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.index64_heap_aux | 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) | 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) =
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 () | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 105,
"start_col": 0,
"start_line": 98
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 () | false |
Vale.X64.Memory.fst | Vale.X64.Memory.load_mem64 | val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 | val load_mem64 (ptr:int) (h:vale_heap) : GTot nat64 | let load_mem64 ptr h =
if not (valid_mem64 ptr h) then 0
else load_mem (TUInt64) ptr h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 436,
"start_col": 0,
"start_line": 434
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Vale.Def.Types_s.nat64 | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.X64.Memory.valid_mem64",
"Prims.bool",
"Vale.X64.Memory.load_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.Def.Types_s.nat64"
] | [] | false | false | false | false | false | let load_mem64 ptr h =
| if not (valid_mem64 ptr h) then 0 else load_mem (TUInt64) ptr h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_buffer | val valid_buffer (t: base_typ) (addr: int) (b: b8) (h: vale_heap) : GTot bool | 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 =
DV.length (get_downview b.bsrc) % (view_n t) = 0 &&
addr_in_ptr #t addr b h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 342,
"start_col": 0,
"start_line": 340
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.store_mem64 | val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap | val store_mem64 (ptr:int) (v:nat64) (h:vale_heap) : GTot vale_heap | let store_mem64 i v h =
if not (valid_mem64 i h) then h
else store_mem (TUInt64) i v h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 475,
"start_col": 0,
"start_line": 473
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Vale.Arch.HeapImpl.vale_heap | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.X64.Memory.valid_mem64",
"Prims.bool",
"Vale.X64.Memory.store_mem",
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | false | false | false | false | false | let store_mem64 i v h =
| if not (valid_mem64 i h) then h else store_mem (TUInt64) i v h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.buffer_write | 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
)) | 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 =
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 308,
"start_col": 0,
"start_line": 293
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Ghost | [] | [] | [
"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"
] | [] | false | false | false | false | false | let buffer_write #t b i v h =
| 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' | false |
Vale.X64.Memory.fst | Vale.X64.Memory.store_mem128 | val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap | val store_mem128 (ptr:int) (v:quad32) (h:vale_heap) : GTot vale_heap | let store_mem128 ptr v h =
if not (valid_mem128 ptr h) then h
else store_mem (TUInt128) ptr v h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 498,
"start_col": 0,
"start_line": 496
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Vale.Arch.HeapImpl.vale_heap | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.X64.Memory.valid_mem128",
"Prims.bool",
"Vale.X64.Memory.store_mem",
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | false | false | false | false | false | let store_mem128 ptr v h =
| if not (valid_mem128 ptr h) then h else store_mem (TUInt128) ptr v h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.get_addr_in_ptr | 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]) | 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: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) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 338,
"start_col": 0,
"start_line": 332
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
n: Prims.nat ->
base: Prims.nat ->
addr: Prims.nat ->
i: Prims.nat
-> Prims.Ghost Prims.nat | Prims.Ghost | [
""
] | [] | [
"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"
] | [
"recursion"
] | false | false | false | false | false | 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]) =
| if base + scale_t t i = addr then i else get_addr_in_ptr t n base addr (i + 1) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_mem_aux | 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)) | 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))
=
match ps with
| [] -> false
| a::q -> valid_buffer t addr a h || valid_mem_aux t addr q h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 358,
"start_col": 0,
"start_line": 350
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Ghost | [] | [] | [
"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"
] | [
"recursion"
] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.load_mem128 | val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32 | val load_mem128 (ptr:int) (h:vale_heap) : GTot quad32 | let load_mem128 ptr h =
if not (valid_mem128 ptr h) then (default_of_typ (TUInt128))
else load_mem (TUInt128) ptr h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 495,
"start_col": 0,
"start_line": 493
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Vale.Def.Types_s.quad32 | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.op_Negation",
"Vale.X64.Memory.valid_mem128",
"Vale.X64.Memory.default_of_typ",
"Vale.Arch.HeapTypes_s.TUInt128",
"Prims.bool",
"Vale.X64.Memory.load_mem",
"Vale.Def.Types_s.quad32"
] | [] | false | false | false | false | false | let load_mem128 ptr h =
| if not (valid_mem128 ptr h) then (default_of_typ (TUInt128)) else load_mem (TUInt128) ptr h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_taint_b8 | val valid_taint_b8 (b: b8) (h: vale_heap) (mt: memtaint) (tn: taint) : GTot prop0 | 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 =
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) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 565,
"start_col": 0,
"start_line": 562
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.find_valid_buffer | 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)) | let find_valid_buffer (t:base_typ) (addr:int) (h:vale_heap) = find_valid_buffer_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 105,
"end_line": 373,
"start_col": 0,
"start_line": 373
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | Prims.GTot | [
"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"
] | [] | false | false | false | false | false | let find_valid_buffer (t: base_typ) (addr: int) (h: vale_heap) =
| find_valid_buffer_aux t addr (_ih h).ptrs h | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.valid_taint_buf | val valid_taint_buf (#t:base_typ) (b:buffer t) (h:vale_heap) (mt:memtaint) (tn:taint) : GTot prop0 | 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 =
valid_taint_b8 b h mt tn | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 568,
"start_col": 0,
"start_line": 567
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.GTot | [
"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"
] | [] | false | false | false | false | false | let valid_taint_buf #t b h mt tn =
| valid_taint_b8 b h mt tn | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_mem | val valid_mem : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | let valid_mem (t:base_typ) addr (h:vale_heap) = valid_mem_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 359,
"start_col": 0,
"start_line": 359
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | Prims.GTot | [
"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"
] | [] | false | false | false | false | false | let valid_mem (t: base_typ) addr (h: vale_heap) =
| valid_mem_aux t addr (_ih h).ptrs h | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.find_valid_buffer_ps | 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) | 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: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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 387,
"start_col": 0,
"start_line": 383
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | 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) =
| find_valid_buffer_aux_ps t addr (_ih h1).ptrs h1 h2 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.same_memTaint64 | 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) | 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 =
same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 607,
"start_col": 0,
"start_line": 606
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let same_memTaint64 b mem0 mem1 memtaint0 memtaint1 =
| same_memTaint (TUInt64) b mem0 mem1 memtaint0 memtaint1 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.find_valid_buffer_aux | 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) | 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)
=
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 371,
"start_col": 0,
"start_line": 362
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | Prims.Ghost | [] | [] | [
"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"
] | [
"recursion"
] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.find_writeable_buffer | 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)) | let find_writeable_buffer (t:base_typ) (addr:int) (h:vale_heap) =
find_writeable_buffer_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 425,
"start_col": 0,
"start_line": 424
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | Prims.GTot | [
"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"
] | [] | false | false | false | false | false | let find_writeable_buffer (t: base_typ) (addr: int) (h: vale_heap) =
| find_writeable_buffer_aux t addr (_ih h).ptrs h | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.valid_taint_bufs | 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 | 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) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 635,
"start_col": 0,
"start_line": 634
} | 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 =
() | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | true | 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) | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.same_memTaint128 | 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) | 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 =
same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 610,
"start_col": 0,
"start_line": 609
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let same_memTaint128 b mem0 mem1 memtaint0 memtaint1 =
| same_memTaint (TUInt128) b mem0 mem1 memtaint0 memtaint1 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.length_t_eq | val length_t_eq (t: base_typ) (b: buffer t)
: Lemma (DV.length (get_downview b.bsrc) == buffer_length b * (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)) =
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) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 444,
"start_col": 0,
"start_line": 438
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.get_addr_ptr | 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) | 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)
=
Some?.v (find_valid_buffer t ptr h) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 450,
"start_col": 0,
"start_line": 446
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.Ghost (Vale.X64.Memory.buffer t) | Prims.Ghost | [] | [] | [
"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"
] | [] | false | false | false | false | 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) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.inv_heaplet_ids | val inv_heaplet_ids : hs: Vale.Arch.HeapImpl.vale_heaplets -> Prims.logical | let inv_heaplet_ids (hs:vale_heaplets) =
forall (i:heaplet_id).{:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 696,
"start_col": 0,
"start_line": 695
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | hs: Vale.Arch.HeapImpl.vale_heaplets -> Prims.logical | Prims.Tot | [
"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"
] | [] | false | false | false | true | true | let inv_heaplet_ids (hs: vale_heaplets) =
| forall (i: heaplet_id). {:pattern Map16.sel hs i} (Map16.sel hs i).heapletId == Some i | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.layout_heaplets_initialized | val layout_heaplets_initialized (layout:vale_heap_layout_inner) : bool | val layout_heaplets_initialized (layout:vale_heap_layout_inner) : bool | let layout_heaplets_initialized layout = layout.vl_heaplets_initialized | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 753,
"start_col": 0,
"start_line": 753
} | 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
) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized",
"Prims.bool"
] | [] | false | false | false | true | false | let layout_heaplets_initialized layout =
| layout.vl_heaplets_initialized | false |
Vale.X64.Memory.fst | Vale.X64.Memory.mem_inv | val mem_inv (h:vale_full_heap) : prop0 | val mem_inv (h:vale_full_heap) : prop0 | 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
) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 751,
"start_col": 0,
"start_line": 742
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: Vale.Arch.HeapImpl.vale_full_heap -> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"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"
] | [] | false | false | false | true | 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) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.writeable_mem_aux | 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)) | 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))
=
match ps with
| [] -> false
| a::q -> writeable_buffer t addr a h || writeable_mem_aux t addr q h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 408,
"start_col": 0,
"start_line": 400
} | 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
))
=
() | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Ghost | [] | [] | [
"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"
] | [
"recursion"
] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.writeable_mem | val writeable_mem : t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | let writeable_mem (t:base_typ) addr (h:vale_heap) = writeable_mem_aux t addr (_ih h).ptrs h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 409,
"start_col": 0,
"start_line": 409
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> addr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot Prims.bool | Prims.GTot | [
"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"
] | [] | false | false | false | false | false | let writeable_mem (t: base_typ) addr (h: vale_heap) =
| writeable_mem_aux t addr (_ih h).ptrs h | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.inv_buffer_info | 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 | 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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 722,
"start_col": 0,
"start_line": 710
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | true | 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)
=
| 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 |
|
Vale.X64.Memory.fst | Vale.X64.Memory.is_initial_heap | val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0 | val is_initial_heap (layout:vale_heap_layout) (h:vale_heap) : prop0 | let is_initial_heap layout h =
h == layout.vl_inner.vl_old_heap /\
not layout.vl_inner.vl_heaplets_initialized | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 740,
"start_col": 0,
"start_line": 738
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout -> h: Vale.Arch.HeapImpl.vale_heap
-> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"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"
] | [] | false | false | false | true | false | let is_initial_heap layout h =
| h == layout.vl_inner.vl_old_heap /\ not layout.vl_inner.vl_heaplets_initialized | false |
Vale.X64.Memory.fst | Vale.X64.Memory.store_mem | 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) | 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)
=
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 471,
"start_col": 0,
"start_line": 463
} | 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
))
=
() | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Ghost | [] | [] | [
"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"
] | [] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.layout_modifies_loc | val layout_modifies_loc (layout:vale_heap_layout_inner) : loc | val layout_modifies_loc (layout:vale_heap_layout_inner) : loc | let layout_modifies_loc layout = layout.vl_mod_loc | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 755,
"start_col": 0,
"start_line": 755
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> Vale.X64.Memory.loc | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_mod_loc",
"Vale.X64.Memory.loc"
] | [] | false | false | false | true | false | let layout_modifies_loc layout =
| layout.vl_mod_loc | false |
Vale.X64.Memory.fst | Vale.X64.Memory.layout_old_heap | val layout_old_heap (layout:vale_heap_layout_inner) : vale_heap | val layout_old_heap (layout:vale_heap_layout_inner) : vale_heap | let layout_old_heap layout = layout.vl_old_heap | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 754,
"start_col": 0,
"start_line": 754
} | 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
) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner -> Vale.Arch.HeapImpl.vale_heap | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_old_heap",
"Vale.Arch.HeapImpl.vale_heap"
] | [] | false | false | false | true | false | let layout_old_heap layout =
| layout.vl_old_heap | false |
Vale.X64.Memory.fst | Vale.X64.Memory.layout_buffers | val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info | val layout_buffers (layout:vale_heap_layout_inner) : Seq.seq buffer_info | let layout_buffers layout = layout.vl_buffers | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 756,
"start_col": 0,
"start_line": 756
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | layout: Vale.Arch.HeapImpl.vale_heap_layout_inner
-> FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info | Prims.Tot | [
"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"
] | [] | false | false | false | true | false | let layout_buffers layout =
| layout.vl_buffers | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_mem128 | val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool | val valid_mem128 (ptr:int) (h:vale_heap) : GTot bool | let valid_mem128 ptr h = valid_mem_aux (TUInt128) ptr (_ih h).ptrs h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 491,
"start_col": 0,
"start_line": 491
} | 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
))
=
() | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool | Prims.GTot | [
"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"
] | [] | false | false | false | false | false | let valid_mem128 ptr h =
| valid_mem_aux (TUInt128) ptr (_ih h).ptrs h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.writeable_mem128 | val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool | val writeable_mem128 (ptr:int) (h:vale_heap) : GTot bool | let writeable_mem128 ptr h = writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 492,
"start_col": 0,
"start_line": 492
} | 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
))
=
() | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> Prims.GTot Prims.bool | Prims.GTot | [
"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"
] | [] | false | false | false | false | false | let writeable_mem128 ptr h =
| writeable_mem_aux (TUInt128) ptr (_ih h).ptrs h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.find_writeable_buffer_aux | 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)) | 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
))
=
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 422,
"start_col": 0,
"start_line": 412
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | Prims.Ghost | [] | [] | [
"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"
] | [
"recursion"
] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.find_valid_buffer_aux_ps | 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) | 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: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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 381,
"start_col": 0,
"start_line": 375
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | false | 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) =
| match ps with
| [] -> ()
| a :: q -> find_valid_buffer_aux_ps t addr q h1 h2 | false |
Vale.AsLowStar.Wrapper.fst | Vale.AsLowStar.Wrapper.stack_of_args_stack_args' | val stack_of_args_stack_args'
(max_arity n: nat)
(args: IX64.arg_list{List.Tot.length args = n})
(init_rsp: MS.nat64{init_rsp >= 4096})
: Lemma
(let mem = Map.const_on Set.empty 0 in
stack_args' max_arity n args init_rsp (IX64.stack_of_args max_arity n init_rsp args mem)) | val stack_of_args_stack_args'
(max_arity n: nat)
(args: IX64.arg_list{List.Tot.length args = n})
(init_rsp: MS.nat64{init_rsp >= 4096})
: Lemma
(let mem = Map.const_on Set.empty 0 in
stack_args' max_arity n args init_rsp (IX64.stack_of_args max_arity n init_rsp args mem)) | let stack_of_args_stack_args'
(max_arity:nat)
(n:nat)
(args:IX64.arg_list{List.Tot.length args = n})
(init_rsp:MS.nat64{init_rsp >= 4096}) : Lemma
(let mem = Map.const_on Set.empty 0 in
stack_args' max_arity n args init_rsp (IX64.stack_of_args max_arity n init_rsp args mem))
=
reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
reveal_opaque (`%BS.valid_addr128) BS.valid_addr128;
let rec aux (args:IX64.arg_list) (accu:Map.t int Vale.Def.Words_s.nat8) : Lemma (ensures (
stack_args' max_arity (List.length args) args init_rsp
(IX64.stack_of_args max_arity (List.length args) init_rsp args accu)))
(decreases (List.length args))
=
reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
reveal_opaque (`%BS.valid_addr128) BS.valid_addr128;
match args with
| [] -> ()
| hd::tl ->
aux tl accu;
let n = List.length args in
if n <= max_arity then ()
else (
let ptr = ((n - max_arity) - 1) * 8 // Arguments on the stack are pushed from right to left
+ (if IA.win then 32 else 0) // The shadow space on Windows comes next
+ 8 // The return address is then pushed on the stack
+ init_rsp // And we then have all the extra slots required for the Vale procedure
in
let accu' = IX64.stack_of_args max_arity (n-1) init_rsp tl accu in
let v = IX64.arg_as_nat64 hd in // We will store the arg hd
let h_final = BS.update_heap64 ptr v accu' in
stack_of_args_stack_args'_aux max_arity (n-1) (n-1) tl init_rsp accu' v;
Vale.Arch.MachineHeap.correct_update_get64 ptr v accu';
BS.update_heap64_reveal ()
)
in aux args (Map.const_on Set.empty 0) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Wrapper.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 421,
"start_col": 0,
"start_line": 383
} | module Vale.AsLowStar.Wrapper
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module I = Vale.Interop
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module SL = Vale.X64.StateLemmas
module VL = Vale.X64.Lemmas
module ST = FStar.HyperStack.ST
open FStar.Mul
open FStar.Calc
//let lemma_create_initial_vale_state_core
// (#max_arity:nat)
// (#reg_arg:IX64.arg_reg_relation max_arity)
// (args:IX64.arg_list)
// (h0:HS.mem{mem_roots_p h0 args})
// : Lemma
// (ensures (
// let s = LSig.create_initial_vale_state #max_arity #reg_arg args h0 in
// hs_of_mem (as_mem s.VS.vs_heap.vf_heap) == h0
// ))
// = ()
#reset-options "--initial_ifuel 2 --max_ifuel 2"
let rec core_create_lemma_disjointness
(args:list arg{disjoint_or_eq args})
: Lemma
(ensures VSig.disjoint_or_eq args)
= match args with
| [] -> ()
| hd::tl ->
disjoint_or_eq_cons hd tl;
BigOps.pairwise_and'_cons VSig.disjoint_or_eq_1 hd tl;
core_create_lemma_disjointness tl;
assert (VSig.disjoint_or_eq tl);
let rec aux (n:list arg)
: Lemma (requires (BigOps.big_and' (disjoint_or_eq_1 hd) n))
(ensures (BigOps.big_and' (VSig.disjoint_or_eq_1 hd) n)) =
match n with
| [] -> ()
| n::ns ->
BigOps.big_and'_cons (disjoint_or_eq_1 hd) n ns;
BigOps.big_and'_cons (VSig.disjoint_or_eq_1 hd) n ns;
aux ns
in
aux tl
#reset-options
#push-options "--z3rlimit 40 --fuel 1 --ifuel 2"
let rec args_b8_lemma (args:list arg) (x:arg)
: Lemma
(List.memP x args ==>
(match x with
| (| TD_Buffer src bt _, x |) -> List.memP (mut_to_b8 src x) (args_b8 args)
| (| TD_ImmBuffer src bt _, x |) -> List.memP (imm_to_b8 src x) (args_b8 args)
| _ -> True))
= match args with
| [] -> ()
| a::q ->
assert (List.memP x q ==> List.memP x args);
args_b8_lemma q x
#pop-options
let readable_cons (hd:arg) (tl:list arg) (s:ME.vale_heap)
: Lemma VSig.(readable (hd::tl) s <==> (readable_one s hd /\ readable tl s))
= BigOps.big_and'_cons VSig.(readable_one s) hd tl
let arg_is_registered_root (h:ME.vale_heap) (a:arg) =
match a with
| (| TD_Buffer src bt _, x |) ->
List.memP (mut_to_b8 src x) (ptrs_of_mem (as_mem h))
| (| TD_ImmBuffer src bt _, x |) ->
List.memP (imm_to_b8 src x) (ptrs_of_mem (as_mem h))
| _ -> true
#set-options "--z3rlimit 20"
let core_create_lemma_readable
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures
(let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
VSig.readable args (ME.get_vale_heap va_s.VS.vs_heap)))
=
let readable_registered_one (a:arg) (h:ME.vale_heap)
: Lemma VSig.(arg_is_registered_root h a <==> readable_one h a)
= match a with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.reveal_readable #src #bt x h;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal src bt x
| (| TD_ImmBuffer src bt ig, x |) ->
Vale.AsLowStar.MemoryHelpers.reveal_imm_readable #src #bt x h;
assert_norm (ME.buffer_readable h (as_vale_immbuffer #src #bt x) <==>
VSig.readable_one h (| TD_ImmBuffer src bt ig, x |))
| (| TD_Base _, _ |) -> ()
in
let rec readable_registered_all
(args:list arg)
(h:ME.vale_heap {forall x. List.memP x args ==> arg_is_registered_root h x})
: Lemma VSig.(readable args h)
= match args with
| [] -> ()
| hd::tl ->
readable_cons hd tl h;
readable_registered_one hd h;
readable_registered_all tl h
in
let readable_mk_mem
(args:list arg)
(h:mem_roots args)
: Lemma
(let mem = mk_mem args h in
VSig.readable args (create_initial_vale_heap mem))
= let mem = mk_mem args h in
FStar.Classical.forall_intro (FStar.Classical.move_requires (args_b8_lemma args));
readable_registered_all args (create_initial_vale_heap mem)
in
readable_mk_mem args h0
let readable_live_one (h:ME.vale_heap) (a:arg)
: Lemma (VSig.readable_one h a ==>
live_arg (hs_of_mem (as_mem h)) a)
= match a with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.readable_live #src #bt x h
| (| TD_ImmBuffer src bt ig, x |) ->
Vale.AsLowStar.MemoryHelpers.readable_imm_live #src #bt x h;
assert_norm (ME.buffer_readable h (as_vale_immbuffer #src #bt x) <==>
VSig.readable_one h (| TD_ImmBuffer src bt ig, x |))
| (| TD_Base _, _ |) -> ()
let rec readable_all_live (h:ME.vale_heap) (args:list arg)
: Lemma (VSig.readable args h ==>
all_live (hs_of_mem (as_mem h)) args)
= match args with
| [] -> ()
| hd::tl ->
readable_cons hd tl h;
all_live_cons hd tl (hs_of_mem (as_mem h));
readable_live_one h hd;
readable_all_live h tl
let core_create_lemma_mem_correspondance
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures
(let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.mem_correspondence args h0 va_s))
=
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let rec aux (accu:list arg) : Lemma
(requires (forall x. List.memP x accu ==> (live_arg h0 x)))
(ensures LSig.mem_correspondence accu h0 va_s) =
match accu with
| [] -> ()
| hd::tl -> aux tl;
match hd with
| (| TD_Buffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.buffer_as_seq_reveal src bt x args h0;
let db = get_downview x in
DV.length_eq db;
let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in
assert (Seq.equal (UV.as_seq h0 ub) (UV.as_seq h0 ub))
| (| TD_ImmBuffer src bt _, x |) ->
Vale.AsLowStar.MemoryHelpers.immbuffer_as_seq_reveal src bt x args h0;
let db = get_downview x in
DV.length_eq db;
let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in
assert (Seq.equal (UV.as_seq h0 ub) (UV.as_seq h0 ub))
| (| TD_Base _, _ |) -> ()
in
BigOps.big_and'_forall (live_arg h0) args;
aux args
let rec register_args'
(max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.length args = n})
(regs:IX64.registers)
: prop
= match args with
| [] -> True
| hd::tl ->
register_args' max_arity arg_reg (n - 1) tl regs /\
(if n > max_arity then True
else regs (arg_reg.IX64.of_arg (n - 1)) == IX64.arg_as_nat64 hd)
let rec lemma_register_args'_aux
(max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.length args = n})
(regs1 regs2:IX64.registers)
: Lemma
(requires
register_args' max_arity arg_reg n args regs1 /\
(forall r. (forall (i:IX64.reg_nat max_arity{i >= n}). r <> (arg_reg.IX64.of_arg i)) /\
r <> MS.rRsp ==>
regs1 r == regs2 r))
(ensures register_args' max_arity arg_reg n args regs2)
= match args with
| [] -> ()
| hd::tl ->
lemma_register_args'_aux max_arity arg_reg (n-1) tl regs1 regs2
let rec lemma_register_args'
(max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(regs:IX64.registers)
: Lemma
(ensures
(let final_regs = IX64.register_of_args max_arity arg_reg (List.length args) args regs in
register_args' max_arity arg_reg (List.length args) args final_regs))
= let final_regs = IX64.register_of_args max_arity arg_reg (List.length args) args regs in
match args with
| [] -> ()
| hd::tl ->
let n = List.length args in
let regs' = (IX64.register_of_args max_arity arg_reg (n-1) tl regs) in
lemma_register_args' max_arity arg_reg tl regs;
lemma_register_args'_aux max_arity arg_reg (n-1) tl regs' final_regs
let core_create_lemma_register_args
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.register_args max_arity arg_reg (List.length args) args va_s))
=
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let regs' = IX64.register_of_args max_arity arg_reg (List.Tot.length args) args IA.init_regs in
lemma_register_args' max_arity arg_reg args IA.init_regs;
let open MS in
let regs = FunctionalExtensionality.on reg_64 regs' in
lemma_register_args'_aux max_arity arg_reg (List.length args) args regs' regs;
assert (register_args' max_arity arg_reg (List.length args) args regs);
let rec aux
(args:IX64.arg_list)
(s:VS.vale_state)
(args':list arg)
(h0:HS.mem{mem_roots_p h0 args'})
: Lemma
(requires
(forall r. VS.eval_reg_64 r s == regs r) /\
register_args' max_arity arg_reg (List.length args) args regs /\
s.VS.vs_heap.vf_heap == create_initial_vale_heap (mk_mem args' h0))
(ensures LSig.register_args max_arity arg_reg (List.length args) args s)
(decreases args)
= let n = List.length args in
match args with
| [] -> ()
| hd::tl -> aux tl s args' h0;
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ -> Vale.AsLowStar.MemoryHelpers.buffer_addr_reveal src bt x args' h0
| TD_ImmBuffer src bt _ -> Vale.AsLowStar.MemoryHelpers.immbuffer_addr_reveal src bt x args' h0
| TD_Base _ -> ()
in
aux args va_s args h0
let core_create_lemma_state
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures
(let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
fst (IX64.create_initial_trusted_state max_arity arg_reg args h0) == SL.state_to_S va_s))
= let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let tr_s = fst (IX64.create_initial_trusted_state max_arity arg_reg args h0) in
let sl_s = SL.state_to_S va_s in
assert (tr_s.BS.ms_stackTaint == va_s.VS.vs_stackTaint);
//SL.lemma_to_ok va_s;
let aux_flag (f:MS.flag) : Lemma (tr_s.BS.ms_flags f == sl_s.BS.ms_flags f)
= ()//SL.lemma_to_flags va_s f
in
Classical.forall_intro aux_flag;
assert (FunctionalExtensionality.feq tr_s.BS.ms_flags sl_s.BS.ms_flags);
//SL.lemma_to_mem va_s;
//SL.lemma_to_stack va_s;
let aux_reg (r:MS.reg) : Lemma (tr_s.BS.ms_regs r == sl_s.BS.ms_regs r)
= ()//SL.lemma_to_reg va_s r
in
Classical.forall_intro aux_reg;
assert (FunctionalExtensionality.feq tr_s.BS.ms_regs sl_s.BS.ms_regs);
// Vale.AsLowStar.MemoryHelpers.get_heap_mk_mem_reveal args h0;
Vale.AsLowStar.MemoryHelpers.mk_stack_reveal tr_s.BS.ms_stack
let rec stack_args' (max_arity:nat)
(n:nat)
(args:list arg{List.Tot.length args = n})
(rsp:int)
(stack:Map.t int Vale.Def.Words_s.nat8)
: prop =
match args with
| [] -> True
| hd::tl ->
stack_args' max_arity (n-1) tl rsp stack /\
(if n <= max_arity then True // This arg is passed in registers
else
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ rsp
in
BS.valid_addr64 ptr stack /\
BS.get_heap_val64 ptr stack == IX64.arg_as_nat64 hd)
let frame_update_get_heap (ptr:int) (v:MS.nat64) (mem:BS.machine_heap) (j:int) : Lemma
(requires ptr >= j + 8)
(ensures BS.get_heap_val64 j mem == BS.get_heap_val64 j (BS.update_heap64 ptr v mem))
=
BS.get_heap_val64_reveal ();
BS.update_heap64_reveal ()
let frame_update_valid_heap (ptr:int) (v:MS.nat64) (mem:BS.machine_heap) (j:int) : Lemma
(requires ptr >= j + 8)
(ensures BS.valid_addr64 j mem == BS.valid_addr64 j (BS.update_heap64 ptr v mem))
=
reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
BS.update_heap64_reveal ()
let rec stack_of_args_stack_args'_aux
(max_arity:nat)
(n_init:nat)
(n:nat)
(args:IX64.arg_list{List.Tot.length args = n})
(rsp:int)
(stack:Map.t int Vale.Def.Words_s.nat8)
(v:MS.nat64)
: Lemma
(requires stack_args' max_arity n args rsp stack /\ n_init >= n)
(ensures
(let ptr = (n_init - max_arity) * 8 + (if IA.win then 32 else 0) + 8 + rsp in
stack_args' max_arity n args rsp (BS.update_heap64 ptr v stack)))
= match args with
| [] -> ()
| hd::tl ->
stack_of_args_stack_args'_aux max_arity n_init (n-1) tl rsp stack v;
if n <= max_arity then ()
else (
let fixed = (n_init - max_arity) * 8 + (if IA.win then 32 else 0) + 8 + rsp in
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ rsp
in
calc ( <= ) {
((n - max_arity) - 1) * 8;
( <= ) { FStar.Math.Lemmas.lemma_mult_le_right 8 ((n - max_arity) - 1) (n_init - max_arity) }
(n_init - max_arity) * 8;
};
frame_update_get_heap fixed v stack ptr;
frame_update_valid_heap fixed v stack ptr
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fsti.checked",
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Lemmas.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.Wrapper.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 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": true,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
max_arity: Prims.nat ->
n: Prims.nat ->
args: Vale.Interop.X64.arg_list{FStar.List.Tot.Base.length args = n} ->
init_rsp: Vale.X64.Machine_s.nat64{init_rsp >= 4096}
-> FStar.Pervasives.Lemma
(ensures
(let mem = FStar.Map.const_on FStar.Set.empty 0 in
Vale.AsLowStar.Wrapper.stack_args' max_arity
n
args
init_rsp
(Vale.Interop.X64.stack_of_args max_arity n init_rsp args mem))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Vale.Interop.X64.arg_list",
"Prims.b2t",
"Prims.op_Equality",
"FStar.List.Tot.Base.length",
"Vale.Interop.Base.arg",
"Vale.X64.Machine_s.nat64",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.const_on",
"Prims.int",
"Vale.Def.Words_s.nat8",
"FStar.Set.empty",
"FStar.Map.t",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.AsLowStar.Wrapper.stack_args'",
"Vale.Interop.X64.stack_of_args",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.list",
"Prims.op_LessThanOrEqual",
"Prims.bool",
"Vale.Arch.MachineHeap_s.update_heap64_reveal",
"Vale.Arch.MachineHeap.correct_update_get64",
"Vale.AsLowStar.Wrapper.stack_of_args_stack_args'_aux",
"Prims.op_Subtraction",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap64",
"Vale.Def.Words_s.nat64",
"Vale.Interop.X64.arg_as_nat64",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Interop.Assumptions.win",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.Arch.MachineHeap_s.valid_addr64"
] | [] | false | false | true | false | false | let stack_of_args_stack_args'
(max_arity n: nat)
(args: IX64.arg_list{List.Tot.length args = n})
(init_rsp: MS.nat64{init_rsp >= 4096})
: Lemma
(let mem = Map.const_on Set.empty 0 in
stack_args' max_arity n args init_rsp (IX64.stack_of_args max_arity n init_rsp args mem)) =
| reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
reveal_opaque (`%BS.valid_addr128) BS.valid_addr128;
let rec aux (args: IX64.arg_list) (accu: Map.t int Vale.Def.Words_s.nat8)
: Lemma
(ensures
(stack_args' max_arity
(List.length args)
args
init_rsp
(IX64.stack_of_args max_arity (List.length args) init_rsp args accu)))
(decreases (List.length args)) =
reveal_opaque (`%BS.valid_addr64) BS.valid_addr64;
reveal_opaque (`%BS.valid_addr128) BS.valid_addr128;
match args with
| [] -> ()
| hd :: tl ->
aux tl accu;
let n = List.length args in
if n <= max_arity
then ()
else
(let ptr = ((n - max_arity) - 1) * 8 + (if IA.win then 32 else 0) + 8 + init_rsp in
let accu' = IX64.stack_of_args max_arity (n - 1) init_rsp tl accu in
let v = IX64.arg_as_nat64 hd in
let h_final = BS.update_heap64 ptr v accu' in
stack_of_args_stack_args'_aux max_arity (n - 1) (n - 1) tl init_rsp accu' v;
Vale.Arch.MachineHeap.correct_update_get64 ptr v accu';
BS.update_heap64_reveal ())
in
aux args (Map.const_on Set.empty 0) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.same_memTaint | 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) | 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) =
assert (Map.equal memT0 memT1) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 604,
"start_col": 0,
"start_line": 600
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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) | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_layout_buffer_id | val valid_layout_buffer_id (t:base_typ) (b:buffer t) (layout:vale_heap_layout) (h_id:option heaplet_id) (write:bool) : prop0 | 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 =
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 693,
"start_col": 0,
"start_line": 688
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.inv_heaplet | val inv_heaplet : owns: FStar.Set.set Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> hi: Vale.Arch.HeapImpl.vale_heap
-> Prims.logical | 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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 707,
"start_col": 0,
"start_line": 698
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | owns: FStar.Set.set Prims.int -> h: Vale.Arch.HeapImpl.vale_heap -> hi: Vale.Arch.HeapImpl.vale_heap
-> Prims.logical | Prims.Tot | [
"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"
] | [] | false | false | false | true | true | 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 |
|
Vale.X64.Memory.fst | Vale.X64.Memory.inv_heaplets | 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 | 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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 736,
"start_col": 0,
"start_line": 724
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | true | 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 /\
(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 | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.lemma_store_mem128 | 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
) | 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 = lemma_store_mem TUInt128 b i v h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 558,
"start_col": 0,
"start_line": 558
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let lemma_store_mem128 b i v h =
| lemma_store_mem TUInt128 b i v h | false |
Vale.X64.Memory.fst | Vale.X64.Memory.lemma_store_mem64 | 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
) | 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 = lemma_store_mem TUInt64 b i v h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 540,
"start_col": 0,
"start_line": 540
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let lemma_store_mem64 b i v h =
| lemma_store_mem TUInt64 b i v h | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_t_512 | val state_t_512 : Type0 | let state_t_512 = Hacl.Streaming.MD.state_64 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 50,
"start_col": 0,
"start_line": 50
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32
let state_t_256 = Hacl.Streaming.MD.state_32 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_64"
] | [] | false | false | false | true | true | let state_t_512 =
| Hacl.Streaming.MD.state_64 | false |
|
Vale.Math.Poly2_s.fsti | Vale.Math.Poly2_s.to_poly | val to_poly (p: poly{poly == D.poly}) : D.poly | val to_poly (p: poly{poly == D.poly}) : D.poly | let to_poly (p:poly{poly == D.poly}) : D.poly = coerce D.poly p | {
"file_name": "vale/specs/math/Vale.Math.Poly2_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 52,
"start_col": 7,
"start_line": 52
} | module Vale.Math.Poly2_s
module D = Vale.Math.Poly2.Defs_s
open FStar.Mul
open FStar.Seq
// Polynomials cn * x^n + ... + c0 * x^0
// where coefficients ck are treated mod 2
// Each coefficient is 0 (false) or 1 (true)
val poly : eqtype
val degree (p:poly) : int // note: degree zero == -1
val zero : poly
val one : poly
val monomial (n:nat) : poly // x^n
val shift (p:poly) (n:int) : poly // x^n * p
val reverse (p:poly) (n:nat) : poly // x^n <--> x^0, x^(n-1) <--> x^1, ...
// Index any coefficient, where all coefficients beyond highest-order term are zero
// (and n < 0 returns zero).
// p.[0] is the coefficient of the lowest-order term (x^0).
val poly_index (p:poly) (n:int) : bool
unfold let ( .[] ) = poly_index
val to_seq (p:poly) (n:nat) : Pure (seq bool)
(requires True)
(ensures fun s ->
length s == n /\
(forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i)
)
val of_seq (s:seq bool) : Pure poly
(requires True)
(ensures fun p ->
degree p < length s /\
(forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i)
)
val of_fun (len:nat) (f:nat -> bool) : Pure poly
(requires True)
(ensures fun p ->
degree p < len /\
(forall (i:nat).{:pattern p.[i] \/ (f i)} i < len ==> p.[i] == f i) /\
(forall (i:int).{:pattern p.[i]} p.[i] ==> 0 <= i /\ i < len)
)
val add (a b:poly) : poly
val mul (a b:poly) : poly
val div (a b:poly) : poly
val mod (a b:poly) : poly | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Poly2.Defs_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2.Defs_s",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Vale.Math.Poly2_s.poly{Vale.Math.Poly2_s.poly == Vale.Math.Poly2.Defs_s.poly}
-> Vale.Math.Poly2.Defs_s.poly | Prims.Tot | [
"total"
] | [] | [
"Vale.Math.Poly2_s.poly",
"Prims.eq2",
"Vale.Math.Poly2.Defs_s.poly",
"Vale.Math.Poly2_s.coerce"
] | [] | false | false | false | false | false | let to_poly (p: poly{poly == D.poly}) : D.poly =
| coerce D.poly p | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_t_224 | val state_t_224 : Type0 | let state_t_224 = Hacl.Streaming.MD.state_32 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 47,
"start_col": 0,
"start_line": 47
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_32"
] | [] | false | false | false | true | true | let state_t_224 =
| Hacl.Streaming.MD.state_32 | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.valid_layout_data_buffer | 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 | 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) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 685,
"start_col": 0,
"start_line": 679
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | true | 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) | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_t_384 | val state_t_384 : Type0 | let state_t_384 = Hacl.Streaming.MD.state_64 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 49,
"start_col": 0,
"start_line": 49
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_64"
] | [] | false | false | false | true | true | let state_t_384 =
| Hacl.Streaming.MD.state_64 | false |
|
Vale.X64.Memory.fst | Vale.X64.Memory.modifies_valid_taint | 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)] | 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 =
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()) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 628,
"start_col": 0,
"start_line": 612
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)
] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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 ()) | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_t_256 | val state_t_256 : Type0 | let state_t_256 = Hacl.Streaming.MD.state_32 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 48,
"start_col": 0,
"start_line": 48
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_32"
] | [] | false | false | false | true | true | let state_t_256 =
| Hacl.Streaming.MD.state_32 | false |
|
Vale.Math.Poly2_s.fsti | Vale.Math.Poly2_s.coerce | val coerce (#a b: Type0) (x: a{a == b}) : b | val coerce (#a b: Type0) (x: a{a == b}) : b | let coerce (#a:Type0) (b:Type0) (x:a{a == b}) : b = x | {
"file_name": "vale/specs/math/Vale.Math.Poly2_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 51,
"start_col": 7,
"start_line": 51
} | module Vale.Math.Poly2_s
module D = Vale.Math.Poly2.Defs_s
open FStar.Mul
open FStar.Seq
// Polynomials cn * x^n + ... + c0 * x^0
// where coefficients ck are treated mod 2
// Each coefficient is 0 (false) or 1 (true)
val poly : eqtype
val degree (p:poly) : int // note: degree zero == -1
val zero : poly
val one : poly
val monomial (n:nat) : poly // x^n
val shift (p:poly) (n:int) : poly // x^n * p
val reverse (p:poly) (n:nat) : poly // x^n <--> x^0, x^(n-1) <--> x^1, ...
// Index any coefficient, where all coefficients beyond highest-order term are zero
// (and n < 0 returns zero).
// p.[0] is the coefficient of the lowest-order term (x^0).
val poly_index (p:poly) (n:int) : bool
unfold let ( .[] ) = poly_index
val to_seq (p:poly) (n:nat) : Pure (seq bool)
(requires True)
(ensures fun s ->
length s == n /\
(forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i)
)
val of_seq (s:seq bool) : Pure poly
(requires True)
(ensures fun p ->
degree p < length s /\
(forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i)
)
val of_fun (len:nat) (f:nat -> bool) : Pure poly
(requires True)
(ensures fun p ->
degree p < len /\
(forall (i:nat).{:pattern p.[i] \/ (f i)} i < len ==> p.[i] == f i) /\
(forall (i:int).{:pattern p.[i]} p.[i] ==> 0 <= i /\ i < len)
)
val add (a b:poly) : poly
val mul (a b:poly) : poly
val div (a b:poly) : poly
val mod (a b:poly) : poly | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Poly2.Defs_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2.Defs_s",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Type0 -> x: a{a == b} -> b | Prims.Tot | [
"total"
] | [] | [
"Prims.eq2"
] | [] | false | false | false | false | false | let coerce (#a b: Type0) (x: a{a == b}) : b =
| x | false |
Vale.X64.Memory.fst | Vale.X64.Memory.valid_memtaint | 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) | 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)
=
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) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 142,
"end_line": 677,
"start_col": 0,
"start_line": 662
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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) | false |
Vale.Math.Poly2_s.fsti | Vale.Math.Poly2_s.of_poly | val of_poly (p: D.poly{poly == D.poly}) : poly | val of_poly (p: D.poly{poly == D.poly}) : poly | let of_poly (p:D.poly{poly == D.poly}) : poly = coerce poly p | {
"file_name": "vale/specs/math/Vale.Math.Poly2_s.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 53,
"start_col": 7,
"start_line": 53
} | module Vale.Math.Poly2_s
module D = Vale.Math.Poly2.Defs_s
open FStar.Mul
open FStar.Seq
// Polynomials cn * x^n + ... + c0 * x^0
// where coefficients ck are treated mod 2
// Each coefficient is 0 (false) or 1 (true)
val poly : eqtype
val degree (p:poly) : int // note: degree zero == -1
val zero : poly
val one : poly
val monomial (n:nat) : poly // x^n
val shift (p:poly) (n:int) : poly // x^n * p
val reverse (p:poly) (n:nat) : poly // x^n <--> x^0, x^(n-1) <--> x^1, ...
// Index any coefficient, where all coefficients beyond highest-order term are zero
// (and n < 0 returns zero).
// p.[0] is the coefficient of the lowest-order term (x^0).
val poly_index (p:poly) (n:int) : bool
unfold let ( .[] ) = poly_index
val to_seq (p:poly) (n:nat) : Pure (seq bool)
(requires True)
(ensures fun s ->
length s == n /\
(forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i)
)
val of_seq (s:seq bool) : Pure poly
(requires True)
(ensures fun p ->
degree p < length s /\
(forall (i:nat).{:pattern (p.[i]) \/ (index s i)} i < length s ==> p.[i] == index s i)
)
val of_fun (len:nat) (f:nat -> bool) : Pure poly
(requires True)
(ensures fun p ->
degree p < len /\
(forall (i:nat).{:pattern p.[i] \/ (f i)} i < len ==> p.[i] == f i) /\
(forall (i:int).{:pattern p.[i]} p.[i] ==> 0 <= i /\ i < len)
)
val add (a b:poly) : poly
val mul (a b:poly) : poly
val div (a b:poly) : poly
val mod (a b:poly) : poly
unfold let coerce (#a:Type0) (b:Type0) (x:a{a == b}) : b = x | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Poly2.Defs_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2_s.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2.Defs_s",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Vale.Math.Poly2.Defs_s.poly{Vale.Math.Poly2_s.poly == Vale.Math.Poly2.Defs_s.poly}
-> Vale.Math.Poly2_s.poly | Prims.Tot | [
"total"
] | [] | [
"Vale.Math.Poly2.Defs_s.poly",
"Prims.eq2",
"Vale.Math.Poly2_s.poly",
"Vale.Math.Poly2_s.coerce"
] | [] | false | false | false | false | false | let of_poly (p: D.poly{poly == D.poly}) : poly =
| coerce poly p | false |
Vale.X64.Memory.fst | Vale.X64.Memory.write_taint_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]) | 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])
=
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 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 659,
"start_col": 0,
"start_line": 637
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [
"recursion"
] | false | false | true | false | 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 | false |
Vale.X64.Memory.fst | Vale.X64.Memory.heaps_match | val heaps_match (bs:Seq.seq buffer_info) (mt:memtaint) (h1 h2:vale_heap) (id:heaplet_id) : prop0 | 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 =
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)) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 768,
"start_col": 0,
"start_line": 758
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | true | 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)) | false |
Hacl.Impl.Curve25519.Generic.fst | Hacl.Impl.Curve25519.Generic.encode_point | val encode_point:
#s:field_spec
-> o:lbuffer uint8 32ul
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ disjoint o i /\
state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.encodePoint (fget_x h0 i, fget_z h0 i)) | val encode_point:
#s:field_spec
-> o:lbuffer uint8 32ul
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ disjoint o i /\
state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.encodePoint (fget_x h0 i, fget_z h0 i)) | let encode_point #s o i =
push_frame();
let x : felem s = sub i 0ul (nlimb s) in
let z : felem s = sub i (nlimb s) (nlimb s) in
let tmp = create_felem s in
let u64s = create 4ul (u64 0) in
let tmp_w = create (2ul `FStar.UInt32.mul` ((nwide s) <: FStar.UInt32.t)) (wide_zero s) in
let h0 = ST.get () in
finv tmp z tmp_w;
fmul tmp tmp x tmp_w;
let h1 = ST.get () in
assert (feval h1 tmp == S.fmul (S.fpow (feval h0 z) (pow2 255 - 21)) (feval h0 x));
assert (feval h1 tmp == S.fmul (feval h0 x) (S.fpow (feval h0 z) (pow2 255 - 21)));
store_felem u64s tmp;
let h2 = ST.get () in
assert (as_seq h2 u64s == BSeq.nat_to_intseq_le 4 (feval h1 tmp));
uints_to_bytes_le #U64 4ul o u64s;
let h3 = ST.get () in
BSeq.uints_to_bytes_le_nat_lemma #U64 #SEC 4 (feval h1 tmp);
assert (as_seq h3 o == BSeq.nat_to_bytes_le 32 (feval h1 tmp));
pop_frame() | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Generic.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 114,
"start_col": 0,
"start_line": 94
} | module Hacl.Impl.Curve25519.Generic
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Curve25519.Fields
include Hacl.Impl.Curve25519.Finv
include Hacl.Impl.Curve25519.AddAndDouble
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
module LSeq = Lib.Sequence
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Spec.Curve25519
module M = Hacl.Spec.Curve25519.AddAndDouble
module Lemmas = Hacl.Spec.Curve25519.Field64.Lemmas
friend Lib.LoopCombinators
#set-options "--z3rlimit 30 --fuel 0 --ifuel 1 --using_facts_from '* -FStar.Seq -Hacl.Spec.*' --record_options"
//#set-options "--debug Hacl.Impl.Curve25519.Generic --debug_level ExtractNorm"
inline_for_extraction noextract
let scalar = lbuffer uint8 32ul
inline_for_extraction noextract
val scalar_bit:
s:scalar
-> n:size_t{v n < 256}
-> Stack uint64
(requires fun h0 -> live h0 s)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.ith_bit (as_seq h0 s) (v n) /\ v r <= 1)
let scalar_bit s n =
let h0 = ST.get () in
mod_mask_lemma ((LSeq.index (as_seq h0 s) (v n / 8)) >>. (n %. 8ul)) 1ul;
assert_norm (1 = pow2 1 - 1);
assert (v (mod_mask #U8 #SEC 1ul) == v (u8 1));
to_u64 ((s.(n /. 8ul) >>. (n %. 8ul)) &. u8 1)
inline_for_extraction noextract
val decode_point:
#s:field_spec
-> o:point s
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
state_inv_t h1 (get_x o) /\ state_inv_t h1 (get_z o) /\
fget_x h1 o == S.decodePoint (as_seq h0 i) /\ fget_z h1 o == 1)
[@ Meta.Attribute.specialize ]
let decode_point #s o i =
push_frame();
let tmp = create 4ul (u64 0) in
let h0 = ST.get () in
uints_from_bytes_le #U64 tmp i;
let h1 = ST.get () in
BSeq.uints_from_bytes_le_nat_lemma #U64 #SEC #4 (as_seq h0 i);
assert (BSeq.nat_from_intseq_le (as_seq h1 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i));
let tmp3 = tmp.(3ul) in
tmp.(3ul) <- tmp3 &. u64 0x7fffffffffffffff;
mod_mask_lemma tmp3 63ul;
assert_norm (0x7fffffffffffffff = pow2 63 - 1);
assert (v (mod_mask #U64 #SEC 63ul) == v (u64 0x7fffffffffffffff));
let h2 = ST.get () in
assert (v (LSeq.index (as_seq h2 tmp) 3) < pow2 63);
Lemmas.lemma_felem64_mod255 (as_seq h1 tmp);
assert (BSeq.nat_from_intseq_le (as_seq h2 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i) % pow2 255);
let x : felem s = sub o 0ul (nlimb s) in
let z : felem s = sub o (nlimb s) (nlimb s) in
set_one z;
load_felem x tmp;
pop_frame()
val encode_point:
#s:field_spec
-> o:lbuffer uint8 32ul
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ disjoint o i /\
state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.encodePoint (fget_x h0 i, fget_z h0 i)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.AddAndDouble.fst.checked",
"Hacl.Impl.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"Hacl.Impl.Curve25519.AddAndDouble.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Generic.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.AddAndDouble",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.AddAndDouble",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Finv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | o: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> i: Hacl.Impl.Curve25519.AddAndDouble.point s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Curve25519.AddAndDouble.point",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.Sequence.seq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.l_or",
"Prims.l_and",
"Prims.nat",
"Lib.Sequence.length",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Impl.Curve25519.Fields.Core.feval",
"Lib.ByteSequence.nat_from_intseq_le",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.ByteSequence.nat_to_bytes_le",
"Lib.ByteSequence.uints_to_bytes_le_nat_lemma",
"Lib.IntTypes.U64",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.ByteBuffer.uints_to_bytes_le",
"Lib.IntTypes.uint64",
"Lib.ByteSequence.nat_to_intseq_le",
"Hacl.Impl.Curve25519.Fields.store_felem",
"Spec.Curve25519.elem",
"Spec.Curve25519.fmul",
"Spec.Curve25519.fpow",
"Prims.op_Subtraction",
"Hacl.Impl.Curve25519.Fields.Core.fmul",
"Hacl.Impl.Curve25519.Finv.finv",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U128",
"FStar.UInt32.mul",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Hacl.Impl.Curve25519.Fields.Core.wide",
"Hacl.Impl.Curve25519.Fields.Core.nwide",
"Hacl.Impl.Curve25519.Fields.Core.wide_zero",
"Lib.IntTypes.u64",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.create_felem",
"Lib.Buffer.sub",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let encode_point #s o i =
| push_frame ();
let x:felem s = sub i 0ul (nlimb s) in
let z:felem s = sub i (nlimb s) (nlimb s) in
let tmp = create_felem s in
let u64s = create 4ul (u64 0) in
let tmp_w = create (2ul `FStar.UInt32.mul` ((nwide s) <: FStar.UInt32.t)) (wide_zero s) in
let h0 = ST.get () in
finv tmp z tmp_w;
fmul tmp tmp x tmp_w;
let h1 = ST.get () in
assert (feval h1 tmp == S.fmul (S.fpow (feval h0 z) (pow2 255 - 21)) (feval h0 x));
assert (feval h1 tmp == S.fmul (feval h0 x) (S.fpow (feval h0 z) (pow2 255 - 21)));
store_felem u64s tmp;
let h2 = ST.get () in
assert (as_seq h2 u64s == BSeq.nat_to_intseq_le 4 (feval h1 tmp));
uints_to_bytes_le #U64 4ul o u64s;
let h3 = ST.get () in
BSeq.uints_to_bytes_le_nat_lemma #U64 #SEC 4 (feval h1 tmp);
assert (as_seq h3 o == BSeq.nat_to_bytes_le 32 (feval h1 tmp));
pop_frame () | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.hacl_sha2_224 | val hacl_sha2_224 : Hacl.Streaming.Interface.block Prims.unit | let hacl_sha2_224 = hacl_md SHA2_224 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 29,
"start_col": 0,
"start_line": 29
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.block Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.hacl_md",
"Spec.Hash.Definitions.SHA2_224"
] | [] | false | false | false | true | false | let hacl_sha2_224 =
| hacl_md SHA2_224 | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.copy_256 | val copy_256 : Hacl.Streaming.Functor.copy_st Hacl.Streaming.SHA2.hacl_sha2_256
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | let copy_256 = F.copy hacl_sha2_256 () (state_256.s ()) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 77,
"start_col": 0,
"start_line": 77
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32
let state_t_256 = Hacl.Streaming.MD.state_32
let state_t_384 = Hacl.Streaming.MD.state_64
let state_t_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_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 malloc_256 = F.malloc hacl_sha2_256 () (state_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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Functor.copy_st Hacl.Streaming.SHA2.hacl_sha2_256
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.copy",
"Prims.unit",
"Hacl.Streaming.SHA2.hacl_sha2_256",
"FStar.Ghost.hide",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.SHA2.state_256",
"FStar.Ghost.erased"
] | [] | false | false | false | false | false | let copy_256 =
| F.copy hacl_sha2_256 () (state_256.s ()) (G.erased unit) | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.hacl_sha2_384 | val hacl_sha2_384 : Hacl.Streaming.Interface.block Prims.unit | let hacl_sha2_384 = hacl_md SHA2_384 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.block Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.hacl_md",
"Spec.Hash.Definitions.SHA2_384"
] | [] | false | false | false | true | false | let hacl_sha2_384 =
| hacl_md SHA2_384 | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_256 | val state_256 : Hacl.Streaming.Interface.stateful Prims.unit | let state_256 = state_t SHA2_256 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 40,
"start_col": 0,
"start_line": 40
} | 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_224 = state_t SHA2_224 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.stateful Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_t",
"Spec.Hash.Definitions.SHA2_256"
] | [] | false | false | false | true | false | let state_256 =
| state_t SHA2_256 | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.reset_256 | val reset_256 : Hacl.Streaming.Functor.reset_st Hacl.Streaming.SHA2.hacl_sha2_256
(FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ())))
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | let reset_256 = F.reset hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 81,
"start_col": 0,
"start_line": 81
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32
let state_t_256 = Hacl.Streaming.MD.state_32
let state_t_384 = Hacl.Streaming.MD.state_64
let state_t_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_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 malloc_256 = F.malloc hacl_sha2_256 () (state_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_256.s ()) (G.erased unit)
[@@ Comment | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Functor.reset_st Hacl.Streaming.SHA2.hacl_sha2_256
(FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ())))
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.reset",
"Prims.unit",
"Hacl.Streaming.SHA2.hacl_sha2_256",
"FStar.Ghost.hide",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.SHA2.state_256",
"FStar.Ghost.erased"
] | [] | false | false | false | false | false | let reset_256 =
| F.reset hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) | false |
|
Steel.ST.GenArraySwap.fst | Steel.ST.GenArraySwap.intro_array_swap_inner_invariant | val intro_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj pidx: R.ref SZ.t)
(b: bool)
(j idx: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit
opened
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(fun _ -> array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) (SZ.v j) (SZ.v idx) b)
(fun _ -> True) | val intro_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj pidx: R.ref SZ.t)
(b: bool)
(j idx: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit
opened
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(fun _ -> array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) (SZ.v j) (SZ.v idx) b)
(fun _ -> True) | let intro_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
(j: SZ.t)
(idx: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit opened
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(fun _ -> array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) (SZ.v j) (SZ.v idx) b)
(fun _ -> True)
= let w = {
j = j;
idx = idx;
s = s;
}
in
rewrite
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s);
rewrite
(array_swap_inner_invariant0 pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b) | {
"file_name": "lib/steel/Steel.ST.GenArraySwap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 64,
"end_line": 352,
"start_col": 0,
"start_line": 320
} | module Steel.ST.GenArraySwap
open Steel.ST.GenElim
module Prf = Steel.ST.GenArraySwap.Proof
module R = Steel.ST.Reference
let gcd_inv_prop
(n0: nat)
(l0: nat)
(n: nat)
(l: nat)
(b: bool)
: Tot prop
= l0 < n0 /\
l < n /\
(Prf.mk_bezout n0 l0).d == (Prf.mk_bezout n l).d /\
b == (l > 0)
[@@__reduce__]
let gcd_inv0
(n0: SZ.t)
(l0: SZ.t)
(pn: R.ref SZ.t)
(pl: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun n -> exists_ (fun l ->
R.pts_to pn full_perm n `star`
R.pts_to pl full_perm l `star`
pure (gcd_inv_prop (SZ.v n0) (SZ.v l0) (SZ.v n) (SZ.v l) b)
))
let gcd_inv
(n0: SZ.t)
(l0: SZ.t)
(pn: R.ref SZ.t)
(pl: R.ref SZ.t)
(b: bool)
: Tot vprop
= gcd_inv0 n0 l0 pn pl b
let gcd_post
(n0: SZ.t)
(l0: SZ.t)
(res: SZ.t)
: Tot prop
= SZ.v l0 < SZ.v n0 /\
SZ.v res == (Prf.mk_bezout (SZ.v n0) (SZ.v l0)).d
#push-options "--z3rlimit 16"
#restart-solver
let gcd
(n0: SZ.t)
(l0: SZ.t)
: ST SZ.t
emp
(fun _ -> emp)
(SZ.v l0 < SZ.v n0)
(fun res -> gcd_post n0 l0 res)
= let res =
R.with_local n0 (fun pn ->
R.with_local l0 (fun pl ->
noop ();
rewrite (gcd_inv0 n0 l0 pn pl (l0 `SZ.gt` 0sz)) (gcd_inv n0 l0 pn pl (l0 `SZ.gt` 0sz));
Steel.ST.Loops.while_loop
(gcd_inv n0 l0 pn pl)
(fun _ ->
let gb = elim_exists () in
rewrite (gcd_inv n0 l0 pn pl gb) (gcd_inv0 n0 l0 pn pl gb);
let _ = gen_elim () in
let l = R.read pl in
[@@inline_let]
let b = l `SZ.gt` 0sz in
noop ();
rewrite (gcd_inv0 n0 l0 pn pl b) (gcd_inv n0 l0 pn pl b);
return b
)
(fun _ ->
rewrite (gcd_inv n0 l0 pn pl true) (gcd_inv0 n0 l0 pn pl true);
let _ = gen_elim () in
let n = R.read pn in
let l = R.read pl in
[@@inline_let]
let l' = SZ.rem n l in
R.write pn l;
R.write pl l';
rewrite (gcd_inv0 n0 l0 pn pl (l' `SZ.gt` 0sz)) (gcd_inv n0 l0 pn pl (l' `SZ.gt` 0sz));
noop ()
);
rewrite (gcd_inv n0 l0 pn pl false) (gcd_inv0 n0 l0 pn pl false);
let _ = gen_elim () in
let res = R.read pn in
return res
)
)
in
elim_pure (gcd_post n0 l0 res);
return res
#pop-options
let array_swap_partial_invariant
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
: GTot prop
= n == Seq.length s0 /\
n == Seq.length s /\
0 < l /\
l < n /\
i <= bz.d /\
(forall (i': Prf.nat_up_to bz.d) .
(forall (j: Prf.nat_up_to bz.q_n) .
(i' < i) ==> (
let idx = Prf.iter_fun #(Prf.nat_up_to n) (Prf.jump n l) j i' in
Seq.index s idx == Seq.index s0 (Prf.jump n l idx)
))) /\
(forall (i': Prf.nat_up_to bz.d) .
(forall (j: Prf.nat_up_to bz.q_n) .
(i' > i) ==> (
let idx = Prf.iter_fun #(Prf.nat_up_to n) (Prf.jump n l) j i' in
Seq.index s idx == Seq.index s0 idx
)))
let array_swap_inner_invariant_prop
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
(j: nat)
(idx: nat)
(b: bool)
: GTot prop
= Prf.array_swap_inner_invariant s0 n l bz s i j idx /\
(b == (j < bz.q_n - 1))
let array_swap_outer_invariant_prop
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
(b: bool)
: GTot prop
= Prf.array_swap_outer_invariant s0 n l bz s i /\
(b == (i < bz.d))
[@@__reduce__]
let array_swap_outer_invariant_body0
(#t: Type)
(pts_to: array_pts_to_t t)
(pi: R.ref SZ.t)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: Tot vprop
=
R.pts_to pi full_perm i `star`
pts_to s
[@@erasable]
noeq
type array_swap_outer_invariant_t (t: Type)
= {
i: SZ.t;
s: Ghost.erased (Seq.seq t);
}
[@@__reduce__]
let array_swap_outer_invariant0
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun w ->
array_swap_outer_invariant_body0 pts_to pi w.i w.s `star`
pure (array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v w.i) b)
)
let array_swap_outer_invariant
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: Tot vprop
= array_swap_outer_invariant0 pts_to n l bz s0 pi b
let intro_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit opened
(array_swap_outer_invariant_body0 pts_to pi i s)
(fun _ -> array_swap_outer_invariant pts_to n l bz s0 pi b)
(array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) b)
(fun _ -> True)
= let w = {
i = i;
s = s;
}
in
rewrite (array_swap_outer_invariant_body0 pts_to pi i s) (array_swap_outer_invariant_body0 pts_to pi w.i w.s);
rewrite (array_swap_outer_invariant0 pts_to n l bz s0 pi b) (array_swap_outer_invariant pts_to n l bz s0 pi b)
let elim_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: STGhost (array_swap_outer_invariant_t t) opened
(array_swap_outer_invariant pts_to n l bz s0 pi b)
(fun w -> array_swap_outer_invariant_body0 pts_to pi w.i w.s)
True
(fun w ->
array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v w.i) b /\
True // (b == false ==> Ghost.reveal w.s `Seq.equal` (Seq.slice s0 (SZ.v l) (SZ.v n) `Seq.append` Seq.slice s0 0 (SZ.v l)))
)
= let w = elim_exists () in
let _ = gen_elim () in
// Classical.move_requires (array_swap_outer_invariant_prop_end (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v w.i)) b;
noop ();
w
[@@erasable]
noeq
type array_swap_inner_invariant_t (t: Type)
= {
j: SZ.t;
idx: SZ.t;
s: Ghost.erased (Seq.seq t)
}
[@@__reduce__]
let array_swap_inner_invariant_body0
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
(j: SZ.t)
(idx: SZ.t)
(s: Ghost.erased (Seq.seq t))
: Tot vprop
= R.pts_to pi full_perm i `star`
R.pts_to pj full_perm j `star`
R.pts_to pidx full_perm idx `star`
pts_to s
[@@__reduce__]
let array_swap_inner_invariant0
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun w ->
array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s `star`
pure (array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v i) (SZ.v w.j) (SZ.v w.idx) b)
)
let array_swap_inner_invariant
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
: Tot vprop
= array_swap_inner_invariant0 pts_to n l bz s0 pi i pj pidx b | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"Steel.ST.GenArraySwap.Proof.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenArraySwap.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.ST.GenArraySwap.Proof",
"short_module": "Prf"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pts_to: Steel.ST.GenArraySwap.array_pts_to_t t ->
n: FStar.SizeT.t ->
l: FStar.SizeT.t ->
bz: Steel.ST.GenArraySwap.Proof.bezout (FStar.SizeT.v n) (FStar.SizeT.v l) ->
s0: FStar.Ghost.erased (FStar.Seq.Base.seq t) ->
pi: Steel.ST.Reference.ref FStar.SizeT.t ->
i: FStar.SizeT.t ->
pj: Steel.ST.Reference.ref FStar.SizeT.t ->
pidx: Steel.ST.Reference.ref FStar.SizeT.t ->
b: Prims.bool ->
j: FStar.SizeT.t ->
idx: FStar.SizeT.t ->
s: FStar.Ghost.erased (FStar.Seq.Base.seq t)
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.ST.GenArraySwap.array_pts_to_t",
"FStar.SizeT.t",
"Steel.ST.GenArraySwap.Proof.bezout",
"FStar.SizeT.v",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Reference.ref",
"Prims.bool",
"Steel.ST.Util.rewrite",
"Steel.ST.GenArraySwap.array_swap_inner_invariant0",
"Steel.ST.GenArraySwap.array_swap_inner_invariant",
"Prims.unit",
"Steel.ST.GenArraySwap.array_swap_inner_invariant_body0",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_inner_invariant_t__item__j",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_inner_invariant_t__item__idx",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_inner_invariant_t__item__s",
"Steel.ST.GenArraySwap.array_swap_inner_invariant_t",
"Steel.ST.GenArraySwap.Mkarray_swap_inner_invariant_t",
"Steel.Effect.Common.vprop",
"Steel.ST.GenArraySwap.array_swap_inner_invariant_prop",
"Prims.l_True"
] | [] | false | true | false | false | false | let intro_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj pidx: R.ref SZ.t)
(b: bool)
(j idx: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit
opened
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(fun _ -> array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) (SZ.v j) (SZ.v idx) b)
(fun _ -> True) =
| let w = { j = j; idx = idx; s = s } in
rewrite (array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s);
rewrite (array_swap_inner_invariant0 pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b) | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.malloc_256 | val malloc_256 : Hacl.Streaming.Functor.malloc_st Hacl.Streaming.SHA2.hacl_sha2_256
()
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | let malloc_256 = F.malloc hacl_sha2_256 () (state_256.s ()) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 70,
"start_col": 0,
"start_line": 70
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32
let state_t_256 = Hacl.Streaming.MD.state_32
let state_t_384 = Hacl.Streaming.MD.state_64
let state_t_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_256.s ()) (G.erased unit)
[@@ Comment
"Allocate initial state for the SHA2_256 hash. The state is to be freed by | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Functor.malloc_st Hacl.Streaming.SHA2.hacl_sha2_256
()
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.malloc",
"Prims.unit",
"Hacl.Streaming.SHA2.hacl_sha2_256",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.SHA2.state_256",
"FStar.Ghost.erased"
] | [] | false | false | false | false | false | let malloc_256 =
| F.malloc hacl_sha2_256 () (state_256.s ()) (G.erased unit) | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.hacl_sha2_512 | val hacl_sha2_512 : Hacl.Streaming.Interface.block Prims.unit | let hacl_sha2_512 = hacl_md SHA2_512 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.block Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.hacl_md",
"Spec.Hash.Definitions.SHA2_512"
] | [] | false | false | false | true | false | let hacl_sha2_512 =
| hacl_md SHA2_512 | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.hacl_sha2_256 | val hacl_sha2_256 : Hacl.Streaming.Interface.block Prims.unit | let hacl_sha2_256 = hacl_md SHA2_256 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 31,
"start_col": 0,
"start_line": 31
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.block Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.hacl_md",
"Spec.Hash.Definitions.SHA2_256"
] | [] | false | false | false | true | false | let hacl_sha2_256 =
| hacl_md SHA2_256 | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.free_256 | 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_256 ())
(FStar.Ghost.erased Prims.unit) | let free_256 = F.free hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 107,
"start_col": 0,
"start_line": 107
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32
let state_t_256 = Hacl.Streaming.MD.state_32
let state_t_384 = Hacl.Streaming.MD.state_64
let state_t_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_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 malloc_256 = F.malloc hacl_sha2_256 () (state_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_256.s ()) (G.erased unit)
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset_256 = F.reset hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit)
[@@ CInline ]
private
let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_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 `reset_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_256.s ()) (G.erased unit) = fun state input input_len -> update_224_256 state input input_len
[@@ Comment
"Write the resulting hash into `output`, an array of 32 bytes. The state remains
valid after a call to `digest_256`, meaning the user may feed more data into
the hash via `update_256`. (The digest_256 function operates on an internal copy of
the state and therefore does not invalidate the client-held state `p`.)"]
let digest_256 = F.digest hacl_sha2_256 () (state_256.s ()) (G.erased unit)
[@@ Comment
"Free a state allocated with `malloc_256`. | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Functor.free_st Hacl.Streaming.SHA2.hacl_sha2_256
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"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_256",
"FStar.Ghost.erased"
] | [] | false | false | false | false | false | let free_256 =
| F.free hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_224 | val state_224 : Hacl.Streaming.Interface.stateful Prims.unit | let state_224 = state_t SHA2_224 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 38,
"start_col": 0,
"start_line": 38
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.stateful Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_t",
"Spec.Hash.Definitions.SHA2_224"
] | [] | false | false | false | true | false | let state_224 =
| state_t SHA2_224 | false |
|
StackMachine.fst | StackMachine.eq_bool | val eq_bool (b1 b2: bool) : Tot bool | val eq_bool (b1 b2: bool) : Tot bool | let eq_bool (b1:bool) (b2:bool) : Tot bool = b1 = b2 | {
"file_name": "examples/metatheory/StackMachine.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module StackMachine
(* A port of http://adam.chlipala.net/cpdt/html/Cpdt.StackMachine.html *)
open FStar.List.Tot
(* Compiling arithmetic expressions to stack machine *)
type binop : Type0 = | Plus | Times
type exp : Type0 =
| Const : nat -> exp
| Binop : binop -> exp -> exp -> exp
let add_nat (n1:nat) (n2:nat) : Tot nat = n1 + n2
let mul_nat (n1:nat) (n2:nat) : Tot nat = n1 `op_Multiply` n2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "StackMachine.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b1: Prims.bool -> b2: Prims.bool -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.op_Equality"
] | [] | false | false | false | true | false | let eq_bool (b1 b2: bool) : Tot bool =
| b1 = b2 | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.alloca_256 | val alloca_256 : Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_256
()
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | let alloca_256 = F.alloca hacl_sha2_256 () (state_256.s ()) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 65,
"start_col": 0,
"start_line": 65
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32
let state_t_256 = Hacl.Streaming.MD.state_32
let state_t_384 = Hacl.Streaming.MD.state_64
let state_t_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
// -------- | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Functor.alloca_st Hacl.Streaming.SHA2.hacl_sha2_256
()
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.alloca",
"Prims.unit",
"Hacl.Streaming.SHA2.hacl_sha2_256",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.SHA2.state_256",
"FStar.Ghost.erased"
] | [] | false | false | false | false | false | let alloca_256 =
| F.alloca hacl_sha2_256 () (state_256.s ()) (G.erased unit) | false |
|
Test.Hash.fst | Test.Hash.test_incremental_api | val test_incremental_api: Prims.unit -> St unit | val test_incremental_api: Prims.unit -> St unit | let test_incremental_api (): St unit =
// Note: this function cannot be in the Stack effect because it performs some
// allocations (even though it frees them afterwards).
push_frame ();
let b1 = B.alloca_of_list [ u8 0x00; u8 0x01; u8 0x02; u8 0x04 ] in
let b2 = B.alloca_of_list [ u8 0x05; u8 0x06; u8 0x07; u8 0x08 ] in
let st = HI.malloc SHA2_256 HyperStack.root in
HI.reset (G.hide SHA2_256) st ();
let h0 = ST.get () in
assert B.(loc_disjoint (S.footprint HI.evercrypt_hash SHA2_256 h0 st) (loc_buffer b1));
assert (S.seen HI.evercrypt_hash SHA2_256 h0 st `Seq.equal` Seq.empty);
assert_norm (4 < pow2 61);
let EverCrypt.Error.Success = HI.update (G.hide SHA2_256) st b1 4ul in
let h1 = ST.get () in
assert (HI.hashed h1 st `Seq.equal` (Seq.append Seq.empty (B.as_seq h0 b1)));
Seq.append_empty_l (B.as_seq h0 b1);
assert (HI.hashed h1 st `Seq.equal` (B.as_seq h0 b1));
assert (Seq.length (Ghost.reveal (Ghost.hide (B.as_seq h0 b1))) = 4);
assert_norm (8 < pow2 61);
let EverCrypt.Error.Success = HI.update (G.hide SHA2_256) st b2 4ul in
let h2 = ST.get () in
assert (HI.hashed h2 st `Seq.equal` (Seq.append (B.as_seq h0 b1) (B.as_seq h0 b2)));
// An example of how to call the hash preservation lemma...
let dst = B.alloca (u8 0) 32ul in
let h3 = ST.get () in
// Auto-framing!
HI.digest (G.hide SHA2_256) st dst ();
let h4 = ST.get () in
assert (Seq.equal (B.as_seq h4 dst)
(Spec.Agile.Hash.hash SHA2_256 (Seq.append (B.as_seq h0 b1) (B.as_seq h0 b2))));
HI.free (G.hide SHA2_256) st;
pop_frame () | {
"file_name": "providers/test/Test.Hash.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 66,
"start_col": 0,
"start_line": 29
} | module Test.Hash
module HI = EverCrypt.Hash.Incremental
module S = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module MP = LowStar.ModifiesPat
module B = LowStar.Buffer
module G = FStar.Ghost
open LowStar.BufferOps
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Lib.IntTypes
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0"
let main (): St unit =
// Nothing here: EverCrypt.Hash is no longer a public API, all clients
// expected to go through HI
() | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.ModifiesPat.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.Hash.Incremental.fst.checked"
],
"interface_file": false,
"source_file": "Test.Hash.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ModifiesPat",
"short_module": "MP"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash.Incremental",
"short_module": "HI"
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.HyperStack.ST.St Prims.unit | FStar.HyperStack.ST.St | [] | [] | [
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"EverCrypt.Hash.Incremental.free",
"FStar.Ghost.hide",
"EverCrypt.Hash.alg",
"Spec.Hash.Definitions.SHA2_256",
"Prims._assert",
"FStar.Seq.Base.equal",
"Hacl.Streaming.Functor.uint8",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.Hash.hash",
"FStar.Seq.Base.append",
"Hacl.Streaming.Interface.uint8",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"EverCrypt.Hash.Incremental.digest",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"Lib.IntTypes.u8",
"FStar.UInt32.__uint_to_t",
"EverCrypt.Hash.Incremental.hashed",
"EverCrypt.Error.error_code",
"EverCrypt.Hash.Incremental.update",
"FStar.Pervasives.assert_norm",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append_empty_l",
"FStar.Seq.Base.empty",
"Hacl.Streaming.Functor.seen",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Streaming.Functor.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"EverCrypt.Hash.Incremental.reset",
"Hacl.Streaming.Functor.state",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"EverCrypt.Hash.Incremental.malloc",
"FStar.Monotonic.HyperHeap.root",
"FStar.Pervasives.normalize_term",
"FStar.List.Tot.Base.length",
"Prims.Cons",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.Nil",
"LowStar.Buffer.alloca_of_list",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let test_incremental_api () : St unit =
| push_frame ();
let b1 = B.alloca_of_list [u8 0x00; u8 0x01; u8 0x02; u8 0x04] in
let b2 = B.alloca_of_list [u8 0x05; u8 0x06; u8 0x07; u8 0x08] in
let st = HI.malloc SHA2_256 HyperStack.root in
HI.reset (G.hide SHA2_256) st ();
let h0 = ST.get () in
assert B.(loc_disjoint (S.footprint HI.evercrypt_hash SHA2_256 h0 st) (loc_buffer b1));
assert ((S.seen HI.evercrypt_hash SHA2_256 h0 st) `Seq.equal` Seq.empty);
assert_norm (4 < pow2 61);
let EverCrypt.Error.Success = HI.update (G.hide SHA2_256) st b1 4ul in
let h1 = ST.get () in
assert ((HI.hashed h1 st) `Seq.equal` (Seq.append Seq.empty (B.as_seq h0 b1)));
Seq.append_empty_l (B.as_seq h0 b1);
assert ((HI.hashed h1 st) `Seq.equal` (B.as_seq h0 b1));
assert (Seq.length (Ghost.reveal (Ghost.hide (B.as_seq h0 b1))) = 4);
assert_norm (8 < pow2 61);
let EverCrypt.Error.Success = HI.update (G.hide SHA2_256) st b2 4ul in
let h2 = ST.get () in
assert ((HI.hashed h2 st) `Seq.equal` (Seq.append (B.as_seq h0 b1) (B.as_seq h0 b2)));
let dst = B.alloca (u8 0) 32ul in
let h3 = ST.get () in
HI.digest (G.hide SHA2_256) st dst ();
let h4 = ST.get () in
assert (Seq.equal (B.as_seq h4 dst)
(Spec.Agile.Hash.hash SHA2_256 (Seq.append (B.as_seq h0 b1) (B.as_seq h0 b2))));
HI.free (G.hide SHA2_256) st;
pop_frame () | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_512 | val state_512 : Hacl.Streaming.Interface.stateful Prims.unit | let state_512 = state_t SHA2_512 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 44,
"start_col": 0,
"start_line": 44
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.stateful Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_t",
"Spec.Hash.Definitions.SHA2_512"
] | [] | false | false | false | true | false | let state_512 =
| state_t SHA2_512 | false |
|
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.update_256 | val update_256:F.update_st hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) | val update_256:F.update_st hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) | let update_256: F.update_st hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) = fun state input input_len -> update_224_256 state input input_len | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 154,
"end_line": 94,
"start_col": 0,
"start_line": 94
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256
inline_for_extraction noextract
let state_384 = state_t SHA2_384
inline_for_extraction noextract
let state_512 = state_t SHA2_512
/// Type abbreviations - for pretty code generation
let state_t_224 = Hacl.Streaming.MD.state_32
let state_t_256 = Hacl.Streaming.MD.state_32
let state_t_384 = Hacl.Streaming.MD.state_64
let state_t_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_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 malloc_256 = F.malloc hacl_sha2_256 () (state_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_256.s ()) (G.erased unit)
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset_256 = F.reset hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit)
[@@ CInline ]
private
let update_224_256 = F.update hacl_sha2_256 (G.hide ()) (state_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 `reset_256`) exceeds 2^61-1 bytes.
This function is identical to the update function for SHA2_224."; | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Functor.update_st Hacl.Streaming.SHA2.hacl_sha2_256
()
(Stateful?.s Hacl.Streaming.SHA2.state_256 ())
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.state",
"Prims.unit",
"Hacl.Streaming.SHA2.hacl_sha2_256",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.SHA2.state_256",
"FStar.Ghost.erased",
"LowStar.Buffer.buffer",
"Hacl.Streaming.Functor.uint8",
"FStar.UInt32.t",
"Hacl.Streaming.SHA2.update_224_256",
"Hacl.Streaming.Types.error_code"
] | [] | false | false | false | false | false | let update_256:F.update_st hacl_sha2_256 (G.hide ()) (state_256.s ()) (G.erased unit) =
| fun state input input_len -> update_224_256 state input input_len | false |
Hacl.Streaming.SHA2.fst | Hacl.Streaming.SHA2.state_384 | val state_384 : Hacl.Streaming.Interface.stateful Prims.unit | let state_384 = state_t SHA2_384 | {
"file_name": "code/streaming/Hacl.Streaming.SHA2.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 42,
"start_col": 0,
"start_line": 42
} | 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_224 = state_t SHA2_224
inline_for_extraction noextract
let state_256 = state_t SHA2_256 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Hacl.Streaming.Interface.stateful Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.MD.state_t",
"Spec.Hash.Definitions.SHA2_384"
] | [] | false | false | false | true | false | let state_384 =
| state_t SHA2_384 | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.