effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Pervasives.Lemma | val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h | val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h = | false | null | true | let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.lemma_load_mem128",
"Prims.unit",
"Vale.X64.Memory.index128_get_heap_val128",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.length",
"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",
"LowStar.BufferView.Down.as_seq",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Vale.X64.Memory.buffer_addr",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.get_addr_ptr",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h)) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h)) | [] | Vale.X64.Memory_Sems.equiv_load_mem128_aux | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem128 ptr h)
(ensures
Vale.X64.Memory.load_mem128 ptr h ==
Vale.Arch.MachineHeap_s.get_heap_val128 ptr (Vale.X64.Memory_Sems.get_heap h)) | {
"end_col": 25,
"end_line": 750,
"start_col": 33,
"start_line": 741
} |
FStar.Pervasives.Lemma | val low_lemma_load_mem128_hi64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val64 (buffer_addr b h + scale16 i + 8) (get_heap h) ==
hi64 (buffer_read b i h)
) | [
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_load_mem128_hi64 b i h =
low_lemma_load_mem128 b i h;
hi64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal () | val low_lemma_load_mem128_hi64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val64 (buffer_addr b h + scale16 i + 8) (get_heap h) ==
hi64 (buffer_read b i h)
)
let low_lemma_load_mem128_hi64 b i h = | false | null | true | low_lemma_load_mem128 b i h;
hi64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal () | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.MachineHeap_s.get_heap_val32_reveal",
"Prims.unit",
"Vale.Arch.MachineHeap_s.get_heap_val64_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.Types.hi64_reveal",
"Vale.X64.Memory_Sems.low_lemma_load_mem128"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
()
#push-options "--smtencoding.l_arith_repr boxwrap"
let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8)
#pop-options
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
let low_lemma_load_mem128_lo64 b i h =
low_lemma_load_mem128 b i h;
lo64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal () | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_load_mem128_hi64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val64 (buffer_addr b h + scale16 i + 8) (get_heap h) ==
hi64 (buffer_read b i h)
) | [] | Vale.X64.Memory_Sems.low_lemma_load_mem128_hi64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.X64.Memory.buffer128 -> i: Prims.nat -> 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)
(ensures
Vale.Arch.MachineHeap_s.get_heap_val64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i +
8)
(Vale.X64.Memory_Sems.get_heap h) ==
Vale.Arch.Types.hi64 (Vale.X64.Memory.buffer_read b i h)) | {
"end_col": 28,
"end_line": 1033,
"start_col": 2,
"start_line": 1029
} |
FStar.Pervasives.Lemma | val lemma_create_heaplets (buffers:list buffer_info) (h1:vale_full_heap) : Lemma
(requires
mem_inv h1 /\
is_initial_heap h1.vf_layout h1.vf_heap /\
init_heaplets_req h1.vf_heap (list_to_seq buffers)
)
(ensures (
let h2 = create_heaplets buffers h1 in
let bs = list_to_seq buffers in
h1.vf_heap == h2.vf_heap /\
h1.vf_heaplets == h2.vf_heaplets /\
h1.vf_layout.vl_taint == h2.vf_layout.vl_taint /\
get_heaplet_id h1.vf_heap == None /\
layout_heaplets_initialized h2.vf_layout.vl_inner /\
layout_modifies_loc h2.vf_layout.vl_inner == loc_mutable_buffers buffers /\
layout_old_heap h2.vf_layout.vl_inner == h1.vf_heap /\
layout_buffers h2.vf_layout.vl_inner == bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> (
let Mkbuffer_info t b hid _ mut = Seq.index bs i in
valid_layout_buffer_id t b h2.vf_layout (Some hid) false /\
valid_layout_buffer_id t b h2.vf_layout (Some hid) (mut = Mutable))) /\
(forall (i:heaplet_id).{:pattern Map16.sel h2.vf_heaplets i}
get_heaplet_id (Map16.sel h2.vf_heaplets i) == Some i /\
heaps_match bs h1.vf_layout.vl_taint h1.vf_heap (Map16.sel h2.vf_heaplets i) i) /\
mem_inv h2
)) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | val lemma_create_heaplets (buffers:list buffer_info) (h1:vale_full_heap) : Lemma
(requires
mem_inv h1 /\
is_initial_heap h1.vf_layout h1.vf_heap /\
init_heaplets_req h1.vf_heap (list_to_seq buffers)
)
(ensures (
let h2 = create_heaplets buffers h1 in
let bs = list_to_seq buffers in
h1.vf_heap == h2.vf_heap /\
h1.vf_heaplets == h2.vf_heaplets /\
h1.vf_layout.vl_taint == h2.vf_layout.vl_taint /\
get_heaplet_id h1.vf_heap == None /\
layout_heaplets_initialized h2.vf_layout.vl_inner /\
layout_modifies_loc h2.vf_layout.vl_inner == loc_mutable_buffers buffers /\
layout_old_heap h2.vf_layout.vl_inner == h1.vf_heap /\
layout_buffers h2.vf_layout.vl_inner == bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> (
let Mkbuffer_info t b hid _ mut = Seq.index bs i in
valid_layout_buffer_id t b h2.vf_layout (Some hid) false /\
valid_layout_buffer_id t b h2.vf_layout (Some hid) (mut = Mutable))) /\
(forall (i:heaplet_id).{:pattern Map16.sel h2.vf_heaplets i}
get_heaplet_id (Map16.sel h2.vf_heaplets i) == Some i /\
heaps_match bs h1.vf_layout.vl_taint h1.vf_heap (Map16.sel h2.vf_heaplets i) i) /\
mem_inv h2
))
let lemma_create_heaplets buffers h1 = | false | null | true | let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs);
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.Arch.HeapImpl.vale_full_heap",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"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",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Vale.X64.Memory_Sems.lemma_loc_mutable_buffers",
"Vale.X64.Memory_Sems.lemma_make_owns",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"FStar.Seq.Base.length",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"Vale.X64.Memory_Sems.create_heaplets",
"Vale.Lib.Seqs.list_to_seq"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2 | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_create_heaplets (buffers:list buffer_info) (h1:vale_full_heap) : Lemma
(requires
mem_inv h1 /\
is_initial_heap h1.vf_layout h1.vf_heap /\
init_heaplets_req h1.vf_heap (list_to_seq buffers)
)
(ensures (
let h2 = create_heaplets buffers h1 in
let bs = list_to_seq buffers in
h1.vf_heap == h2.vf_heap /\
h1.vf_heaplets == h2.vf_heaplets /\
h1.vf_layout.vl_taint == h2.vf_layout.vl_taint /\
get_heaplet_id h1.vf_heap == None /\
layout_heaplets_initialized h2.vf_layout.vl_inner /\
layout_modifies_loc h2.vf_layout.vl_inner == loc_mutable_buffers buffers /\
layout_old_heap h2.vf_layout.vl_inner == h1.vf_heap /\
layout_buffers h2.vf_layout.vl_inner == bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> (
let Mkbuffer_info t b hid _ mut = Seq.index bs i in
valid_layout_buffer_id t b h2.vf_layout (Some hid) false /\
valid_layout_buffer_id t b h2.vf_layout (Some hid) (mut = Mutable))) /\
(forall (i:heaplet_id).{:pattern Map16.sel h2.vf_heaplets i}
get_heaplet_id (Map16.sel h2.vf_heaplets i) == Some i /\
heaps_match bs h1.vf_layout.vl_taint h1.vf_heap (Map16.sel h2.vf_heaplets i) i) /\
mem_inv h2
)) | [] | Vale.X64.Memory_Sems.lemma_create_heaplets | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | buffers: Prims.list Vale.Arch.HeapImpl.buffer_info -> h1: Vale.Arch.HeapImpl.vale_full_heap
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Memory.mem_inv h1 /\
Vale.X64.Memory.is_initial_heap (Mkvale_full_heap?.vf_layout h1)
(Mkvale_full_heap?.vf_heap h1) /\
Vale.X64.Memory.init_heaplets_req (Mkvale_full_heap?.vf_heap h1)
(Vale.Lib.Seqs.list_to_seq buffers))
(ensures
(let h2 = Vale.X64.Memory_Sems.create_heaplets buffers h1 in
let bs = Vale.Lib.Seqs.list_to_seq buffers in
Mkvale_full_heap?.vf_heap h1 == Mkvale_full_heap?.vf_heap h2 /\
Mkvale_full_heap?.vf_heaplets h1 == Mkvale_full_heap?.vf_heaplets h2 /\
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout h1) ==
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout h2) /\
Vale.X64.Memory.get_heaplet_id (Mkvale_full_heap?.vf_heap h1) ==
FStar.Pervasives.Native.None /\
Vale.X64.Memory.layout_heaplets_initialized (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout
h2)) /\
Vale.X64.Memory.layout_modifies_loc (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout
h2)) ==
Vale.X64.Memory.loc_mutable_buffers buffers /\
Vale.X64.Memory.layout_old_heap (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout
h2)) ==
Mkvale_full_heap?.vf_heap h1 /\
Vale.X64.Memory.layout_buffers (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout h2
)) ==
bs /\
(forall (i: Prims.nat). {:pattern FStar.Seq.Base.index bs i}
i < FStar.Seq.Base.length bs ==>
(let _ = FStar.Seq.Base.index bs i in
(let
{ bi_typ = t ; bi_buffer = b ; bi_heaplet = hid ; bi_taint = _ ; bi_mutable = mut
} =
_
in
Vale.X64.Memory.valid_layout_buffer_id t
b
(Mkvale_full_heap?.vf_layout h2)
(FStar.Pervasives.Native.Some hid)
false /\
Vale.X64.Memory.valid_layout_buffer_id t
b
(Mkvale_full_heap?.vf_layout h2)
(FStar.Pervasives.Native.Some hid)
(mut = Vale.Arch.HeapImpl.Mutable))
<:
Prims.logical)) /\
(forall (i: Vale.Arch.HeapImpl.heaplet_id).
{:pattern Vale.Lib.Map16.sel (Mkvale_full_heap?.vf_heaplets h2) i}
Vale.X64.Memory.get_heaplet_id (Vale.Lib.Map16.sel (Mkvale_full_heap?.vf_heaplets h2)
i) ==
FStar.Pervasives.Native.Some i /\
Vale.X64.Memory.heaps_match bs
(Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout h1))
(Mkvale_full_heap?.vf_heap h1)
(Vale.Lib.Map16.sel (Mkvale_full_heap?.vf_heaplets h2) i)
i) /\ Vale.X64.Memory.mem_inv h2)) | {
"end_col": 4,
"end_line": 186,
"start_col": 38,
"start_line": 179
} |
FStar.Pervasives.Lemma | val low_lemma_load_mem128_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | val low_lemma_load_mem128_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
))
let low_lemma_load_mem128_full b i vfh t hid = | false | null | true | reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2 | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_load_mem128_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
)) | [] | Vale.X64.Memory_Sems.low_lemma_load_mem128_full | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h false /\
Vale.X64.Memory.valid_taint_buf128 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale16 i in
Vale.X64.Memory_Sems.is_full_read (Mkvale_full_heap?.vf_heap vfh) h b i /\
Vale.X64.Memory.valid_mem128 ptr (Mkvale_full_heap?.vf_heap vfh) /\
Vale.X64.Memory.valid_taint_buf128 b (Mkvale_full_heap?.vf_heap vfh) mt t)
<:
Type0)) | {
"end_col": 4,
"end_line": 977,
"start_col": 2,
"start_line": 976
} |
FStar.Pervasives.Lemma | val written_buffer_down128 (b: buffer128) (i: nat{i < buffer_length b}) (v: quad32) (h: vale_heap)
: Lemma (requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i + 1) <= j /\ j < base + scale16 n) ==>
mem1.[ j ] == mem2.[ j ])) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2 | val written_buffer_down128 (b: buffer128) (i: nat{i < buffer_length b}) (v: quad32) (h: vale_heap)
: Lemma (requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i + 1) <= j /\ j < base + scale16 n) ==>
mem1.[ j ] == mem2.[ j ]))
let written_buffer_down128 (b: buffer128) (i: nat{i < buffer_length b}) (v: quad32) (h: vale_heap)
: Lemma (requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i + 1) <= j /\ j < base + scale16 n) ==>
mem1.[ j ] == mem2.[ j ])) = | false | null | true | let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i + 1) h1 mem1 mem2 | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory_Sems.written_buffer_down128_aux2",
"Prims.op_Addition",
"Prims.unit",
"Vale.X64.Memory_Sems.written_buffer_down128_aux1",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Prims.l_and",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.X64.Memory.buffer_writeable",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"Vale.X64.Memory.scale16",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==> | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val written_buffer_down128 (b: buffer128) (i: nat{i < buffer_length b}) (v: quad32) (h: vale_heap)
: Lemma (requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i + 1) <= j /\ j < base + scale16 n) ==>
mem1.[ j ] == mem2.[ j ])) | [] | Vale.X64.Memory_Sems.written_buffer_down128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.memP b (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h)) /\
Vale.X64.Memory.buffer_writeable b)
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
let base = Vale.X64.Memory.buffer_addr b h in
let n = Vale.X64.Memory.buffer_length b in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base <= j /\ j < base + Vale.X64.Memory.scale16 i \/
base + Vale.X64.Memory.scale16 (i + 1) <= j /\ j < base + Vale.X64.Memory.scale16 n ==>
mem1.[ j ] == mem2.[ j ])) | {
"end_col": 65,
"end_line": 875,
"start_col": 3,
"start_line": 869
} |
FStar.Pervasives.Lemma | val store_buffer_aux_down64_mem (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h | val store_buffer_aux_down64_mem (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ]))
let store_buffer_aux_down64_mem (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) = | false | null | true | let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i + 1) == ptr + 8);
store_buffer_down64_mem b i v h | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.b2t",
"Vale.X64.Memory.writeable_mem64",
"Vale.X64.Memory_Sems.store_buffer_down64_mem",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale8",
"Vale.X64.Memory.store_buffer_write",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapImpl.buffer",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.find_writeable_buffer",
"Vale.X64.Memory.store_mem",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==> | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_buffer_aux_down64_mem (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) | [] | Vale.X64.Memory_Sems.store_buffer_aux_down64_mem | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ptr: Prims.int ->
v: Vale.Def.Words_s.nat64 ->
h: Vale.Arch.HeapImpl.vale_heap{Vale.X64.Memory.writeable_mem64 ptr h}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.store_mem Vale.Arch.HeapTypes_s.TUInt64 ptr v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) | {
"end_col": 35,
"end_line": 431,
"start_col": 3,
"start_line": 423
} |
FStar.Pervasives.Lemma | val store_buffer_aux_down64_mem2 (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v)) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i | val store_buffer_aux_down64_mem2 (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
let store_buffer_aux_down64_mem2 (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v)) = | false | null | true | let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.b2t",
"Vale.X64.Memory.writeable_mem64",
"Vale.X64.Memory.index64_get_heap_val64",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.X64.Memory.base_typ_as_vale_type",
"FStar.Seq.Base.index",
"Vale.X64.Memory.buffer_as_seq",
"Vale.X64.Memory.store_buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory.store_mem",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapImpl.buffer",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.find_writeable_buffer",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.l_True",
"Prims.squash",
"Vale.Arch.MachineHeap_s.get_heap_val64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_buffer_aux_down64_mem2 (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v)) | [] | Vale.X64.Memory_Sems.store_buffer_aux_down64_mem2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ptr: Prims.int ->
v: Vale.Def.Words_s.nat64 ->
h: Vale.Arch.HeapImpl.vale_heap{Vale.X64.Memory.writeable_mem64 ptr h}
-> FStar.Pervasives.Lemma
(ensures
(let h1 = Vale.X64.Memory.store_mem Vale.Arch.HeapTypes_s.TUInt64 ptr v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
Vale.Arch.MachineHeap_s.get_heap_val64 ptr mem2 == v)) | {
"end_col": 38,
"end_line": 447,
"start_col": 3,
"start_line": 439
} |
FStar.Pervasives.Lemma | val low_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 (
let m = S.update_heap64 (buffer_addr b h + scale8 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap' | val low_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 (
let m = S.update_heap64 (buffer_addr b h + scale8 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
))
let low_lemma_store_mem64 b i v h = | false | null | true | lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap' | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer64",
"Prims.nat",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.update_buffer_up_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.unit",
"Vale.Interop.addrs_set_lemma_all",
"Vale.X64.Memory_Sems.in_bounds64",
"Vale.Arch.MachineHeap.frame_update_heap64",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint64",
"Vale.X64.Memory.scale8",
"Vale.X64.Memory_Sems.low_lemma_store_mem64_aux",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap64",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap",
"Vale.X64.Memory_Sems.valid_state_store_mem64_aux",
"Vale.X64.Memory.lemma_store_mem64",
"Vale.X64.Memory.lemma_writeable_mem64"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver | false | false | Vale.X64.Memory_Sems.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_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 (
let m = S.update_heap64 (buffer_addr b h + scale8 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
)) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64 ->
i: Prims.nat ->
v: Vale.Def.Words_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
(let m =
Vale.Arch.MachineHeap_s.update_heap64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale8 i)
v
(Vale.X64.Memory_Sems.get_heap h)
in
Vale.Arch.MachineHeap_s.is_machine_heap_update (Vale.X64.Memory_Sems.get_heap h) m /\
Vale.X64.Memory_Sems.upd_heap h m == Vale.X64.Memory.buffer_write b i v h)) | {
"end_col": 45,
"end_line": 652,
"start_col": 2,
"start_line": 643
} |
FStar.Pervasives.Lemma | val low_lemma_load_mem128_lo_hi_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
valid_addr64 (ptr + 8) (heap_get (coerce vfh)) /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
)) | [
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_load_mem128_lo_hi_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_valid_mem128_64 b i vfh.vf_heap;
() | val low_lemma_load_mem128_lo_hi_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
valid_addr64 (ptr + 8) (heap_get (coerce vfh)) /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
))
let low_lemma_load_mem128_lo_hi_full b i vfh t hid = | false | null | true | reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_valid_mem128_64 b i vfh.vf_heap;
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.unit",
"Vale.X64.Memory_Sems.low_lemma_valid_mem128_64",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
()
#push-options "--smtencoding.l_arith_repr boxwrap"
let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8)
#pop-options
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
let low_lemma_load_mem128_lo64 b i h =
low_lemma_load_mem128 b i h;
lo64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
let low_lemma_load_mem128_hi64 b i h =
low_lemma_load_mem128 b i h;
hi64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
//let same_domain_update128_64 b i v h =
// low_lemma_valid_mem128_64 b i (_ih h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i) v (get_heap h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i + 8) v (get_heap h)
open Vale.Def.Types_s
let frame_get_heap32 (ptr:int) (mem1 mem2:S.machine_heap) : Lemma
(requires (forall i. i >= ptr /\ i < ptr + 4 ==> mem1.[i] == mem2.[i]))
(ensures S.get_heap_val32 ptr mem1 == S.get_heap_val32 ptr mem2) =
S.get_heap_val32_reveal ()
let update_heap128_lo (ptr:int) (v:quad32) (mem:S.machine_heap) : Lemma
(requires
S.valid_addr128 ptr mem /\
v.hi2 == S.get_heap_val32 (ptr+8) mem /\
v.hi3 == S.get_heap_val32 (ptr+12) mem
)
(ensures S.update_heap128 ptr v mem ==
S.update_heap32 (ptr+4) v.lo1 (S.update_heap32 ptr v.lo0 mem)) =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
S.update_heap128_reveal ();
let mem0 = S.update_heap32 ptr v.lo0 mem in
let mem1 = S.update_heap32 (ptr+4) v.lo1 mem0 in
Vale.Arch.MachineHeap.frame_update_heap32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.frame_update_heap32 (ptr+4) v.lo1 mem0;
Vale.Arch.MachineHeap.same_domain_update32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.same_domain_update32 (ptr+4) v.lo1 mem0;
frame_get_heap32 (ptr+8) mem mem1;
frame_get_heap32 (ptr+12) mem mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+8) mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+12) mem1 | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_load_mem128_lo_hi_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
valid_addr64 (ptr + 8) (heap_get (coerce vfh)) /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
)) | [] | Vale.X64.Memory_Sems.low_lemma_load_mem128_lo_hi_full | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h false /\
Vale.X64.Memory.valid_taint_buf128 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale16 i in
Vale.X64.Memory_Sems.is_full_read (Mkvale_full_heap?.vf_heap vfh) h b i /\
Vale.Arch.MachineHeap_s.valid_addr64 ptr
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)) /\
Vale.Arch.MachineHeap_s.valid_addr64 (ptr + 8)
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)) /\
Vale.X64.Memory.valid_mem128 ptr (Mkvale_full_heap?.vf_heap vfh) /\
Vale.X64.Memory.valid_taint_buf128 b (Mkvale_full_heap?.vf_heap vfh) mt t)
<:
Type0)) | {
"end_col": 4,
"end_line": 1071,
"start_col": 2,
"start_line": 1069
} |
FStar.Pervasives.Lemma | val store_buffer_down64_mem
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux | val store_buffer_down64_mem
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ]))
let store_buffer_down64_mem
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) = | false | null | true | let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j: int)
: Lemma (j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ]) =
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc)
then
(written_buffer_down64 b i v h;
length_t_eq (TUInt64) b)
else
if not (I.valid_addr (_ih h) j)
then
I.same_unspecified_down (IB.hs_of_mem (_ih h))
(IB.hs_of_mem (_ih h1))
(IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"FStar.Classical.forall_intro",
"Prims.int",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"Prims.op_GreaterThanOrEqual",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.X64.Memory.scale_by",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_AmpAmp",
"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.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.X64.Memory_Sems.written_buffer_down64",
"Prims.bool",
"Prims.op_Negation",
"Vale.Interop.valid_addr",
"Vale.Interop.same_unspecified_down",
"Vale.Interop.Heap_s.hs_of_mem",
"Vale.X64.Memory_Sems.unwritten_buffer_down",
"Vale.Interop.addrs_set_lemma_all",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Prims.l_Forall"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==> | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_buffer_down64_mem
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | [] | Vale.X64.Memory_Sems.store_buffer_down64_mem | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
let base = Vale.X64.Memory.buffer_addr b h in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + Vale.X64.Memory.scale8 i \/ j >= base + Vale.X64.Memory.scale8 (i + 1) ==>
mem1.[ j ] == mem2.[ j ])) | {
"end_col": 30,
"end_line": 412,
"start_col": 3,
"start_line": 393
} |
FStar.Pervasives.Lemma | val written_buffer_down128_aux2
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale16 (i + 1) <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale16 (i + 1) /\ j < base + scale16 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end | val written_buffer_down128_aux2
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale16 (i + 1) <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale16 (i + 1) /\ j < base + scale16 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k])
let rec written_buffer_down128_aux2
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale16 (i + 1) <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale16 (i + 1) /\ j < base + scale16 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) = | false | null | true | if k >= n
then ()
else
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k + 1) h1 mem1 mem2 | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma",
""
] | [
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Prims.op_GreaterThan",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale16",
"FStar.Mul.op_Star",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Vale.X64.Memory_Sems.written_buffer_down128_aux2",
"Prims.unit",
"Vale.X64.Memory_Sems.heap_shift",
"Vale.X64.Memory_Sems.same_mem_get_heap_val128",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j])) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val written_buffer_down128_aux2
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale16 (i + 1) <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale16 (i + 1) /\ j < base + scale16 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) | [
"recursion"
] | Vale.X64.Memory_Sems.written_buffer_down128_aux2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h))} ->
base: Prims.nat{base == Vale.X64.Memory.buffer_addr b h} ->
n: Prims.nat{n == Vale.X64.Memory.buffer_length b} ->
k: Prims.nat{k > i} ->
h1: Vale.Arch.HeapImpl.vale_heap{h1 == Vale.X64.Memory.buffer_write b i v h} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h) mem1} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{ Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h1) mem2 /\
(forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base + Vale.X64.Memory.scale16 (i + 1) <= j /\ j < base + k * 16 ==>
mem1.[ j ] == mem2.[ j ]) }
-> FStar.Pervasives.Lemma
(ensures
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j >= base + Vale.X64.Memory.scale16 (i + 1) /\ j < base + Vale.X64.Memory.scale16 n ==>
mem1.[ j ] == mem2.[ j ]) (decreases n - k) | {
"end_col": 7,
"end_line": 854,
"start_col": 4,
"start_line": 848
} |
FStar.Pervasives.Lemma | val written_buffer_down128_aux1
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale16 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end | val written_buffer_down128_aux1
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale16 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k])
let rec written_buffer_down128_aux1
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale16 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) = | false | null | true | if k >= i
then ()
else
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k + 1) h1 mem1 mem2 | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma",
""
] | [
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Vale.X64.Memory_Sems.written_buffer_down128_aux1",
"Prims.unit",
"Vale.X64.Memory_Sems.heap_shift",
"Vale.X64.Memory_Sems.same_mem_get_heap_val128",
"Vale.X64.Memory.scale16",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j])) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val written_buffer_down128_aux1
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale16 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | [
"recursion"
] | Vale.X64.Memory_Sems.written_buffer_down128_aux1 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h))} ->
base: Prims.nat{base == Vale.X64.Memory.buffer_addr b h} ->
k: Prims.nat ->
h1: Vale.Arch.HeapImpl.vale_heap{h1 == Vale.X64.Memory.buffer_write b i v h} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h) mem1} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{ Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h1) mem2 /\
(forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) }
-> FStar.Pervasives.Lemma
(ensures
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem1.[ j ]}
j >= base /\ j < base + Vale.X64.Memory.scale16 i ==> mem1.[ j ] == mem2.[ j ])
(decreases i - k) | {
"end_col": 7,
"end_line": 827,
"start_col": 4,
"start_line": 821
} |
FStar.Pervasives.Lemma | val low_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 (
let m = S.update_heap128 (buffer_addr b h + scale16 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap' | val low_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 (
let m = S.update_heap128 (buffer_addr b h + scale16 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
))
let low_lemma_store_mem128 b i v h = | false | null | true | lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap' | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.update_buffer_up_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.unit",
"Vale.Interop.addrs_set_lemma_all",
"Vale.X64.Memory_Sems.in_bounds128",
"Vale.Arch.MachineHeap.frame_update_heap128",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.scale16",
"Vale.X64.Memory_Sems.low_lemma_store_mem128_aux",
"Vale.X64.Memory.store_mem128",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap128",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap",
"Vale.X64.Memory_Sems.valid_state_store_mem128_aux",
"Vale.X64.Memory.lemma_store_mem128",
"Vale.X64.Memory.lemma_valid_mem128"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_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 (
let m = S.update_heap128 (buffer_addr b h + scale16 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
)) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
v: Vale.X64.Memory.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
(let m =
Vale.Arch.MachineHeap_s.update_heap128 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
v
(Vale.X64.Memory_Sems.get_heap h)
in
Vale.Arch.MachineHeap_s.is_machine_heap_update (Vale.X64.Memory_Sems.get_heap h) m /\
Vale.X64.Memory_Sems.upd_heap h m == Vale.X64.Memory.buffer_write b i v h)) | {
"end_col": 45,
"end_line": 990,
"start_col": 2,
"start_line": 980
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem128_hi64 (b:buffer128) (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 (
let v' = insert_nat64 (buffer_read b i h) v 1 in
let m = S.update_heap64 (buffer_addr b h + scale16 i + 8) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v' h)
) | [
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem128_hi64 b i v h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 1 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
assert (S.valid_addr128 ptr (get_heap h));
Vale.Arch.MachineHeap.update_heap32_get_heap32 ptr (get_heap h);
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+4) (get_heap h);
S.get_heap_val128_reveal ();
S.update_heap128_reveal ();
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal () | val low_lemma_store_mem128_hi64 (b:buffer128) (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 (
let v' = insert_nat64 (buffer_read b i h) v 1 in
let m = S.update_heap64 (buffer_addr b h + scale16 i + 8) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v' h)
)
let low_lemma_store_mem128_hi64 b i v h = | false | null | true | reveal_opaque (`%S.valid_addr128) S.valid_addr128;
let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 1 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
assert (S.valid_addr128 ptr (get_heap h));
Vale.Arch.MachineHeap.update_heap32_get_heap32 ptr (get_heap h);
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr + 4) (get_heap h);
S.get_heap_val128_reveal ();
S.update_heap128_reveal ();
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal () | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Def.Types_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Def.Types_s.insert_nat64_reveal",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap32_reveal",
"Vale.Arch.MachineHeap_s.update_heap64_reveal",
"Vale.Arch.MachineHeap_s.update_heap128_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.MachineHeap.update_heap32_get_heap32",
"Prims.op_Addition",
"Vale.X64.Memory_Sems.get_heap",
"Prims._assert",
"Prims.b2t",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.X64.Memory_Sems.low_lemma_store_mem128",
"Vale.X64.Memory_Sems.low_lemma_load_mem128",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.insert_nat64",
"Vale.X64.Memory.base_typ_as_vale_type",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.X64.Memory.buffer_read",
"Vale.X64.Memory.vuint128",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale16",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.bool"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
()
#push-options "--smtencoding.l_arith_repr boxwrap"
let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8)
#pop-options
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
let low_lemma_load_mem128_lo64 b i h =
low_lemma_load_mem128 b i h;
lo64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
let low_lemma_load_mem128_hi64 b i h =
low_lemma_load_mem128 b i h;
hi64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
//let same_domain_update128_64 b i v h =
// low_lemma_valid_mem128_64 b i (_ih h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i) v (get_heap h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i + 8) v (get_heap h)
open Vale.Def.Types_s
let frame_get_heap32 (ptr:int) (mem1 mem2:S.machine_heap) : Lemma
(requires (forall i. i >= ptr /\ i < ptr + 4 ==> mem1.[i] == mem2.[i]))
(ensures S.get_heap_val32 ptr mem1 == S.get_heap_val32 ptr mem2) =
S.get_heap_val32_reveal ()
let update_heap128_lo (ptr:int) (v:quad32) (mem:S.machine_heap) : Lemma
(requires
S.valid_addr128 ptr mem /\
v.hi2 == S.get_heap_val32 (ptr+8) mem /\
v.hi3 == S.get_heap_val32 (ptr+12) mem
)
(ensures S.update_heap128 ptr v mem ==
S.update_heap32 (ptr+4) v.lo1 (S.update_heap32 ptr v.lo0 mem)) =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
S.update_heap128_reveal ();
let mem0 = S.update_heap32 ptr v.lo0 mem in
let mem1 = S.update_heap32 (ptr+4) v.lo1 mem0 in
Vale.Arch.MachineHeap.frame_update_heap32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.frame_update_heap32 (ptr+4) v.lo1 mem0;
Vale.Arch.MachineHeap.same_domain_update32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.same_domain_update32 (ptr+4) v.lo1 mem0;
frame_get_heap32 (ptr+8) mem mem1;
frame_get_heap32 (ptr+12) mem mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+8) mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+12) mem1
let low_lemma_load_mem128_lo_hi_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_valid_mem128_64 b i vfh.vf_heap;
()
let low_lemma_store_mem128_lo64 b i v h =
let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 0 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
S.get_heap_val128_reveal ();
update_heap128_lo ptr v' (get_heap h);
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal ()
let low_lemma_store_mem128_lo64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let v' = insert_nat64 (buffer_read b i hk) v 0 in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v' (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v' hk in
let mhk' = S.update_heap128 ptr v' (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v' h;
low_lemma_store_mem128 b i v' (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v' t;
low_lemma_store_mem128_lo64 b i v h;
low_lemma_valid_mem128_64 b i h;
assert (Map.equal mt (S.update_n (buffer_addr b h + scale16 i) 8 mt t));
()
#push-options "--z3rlimit 20 --using_facts_from '* -LowStar.Monotonic.Buffer.loc_disjoint_includes_r'"
#restart-solver | false | false | Vale.X64.Memory_Sems.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem128_hi64 (b:buffer128) (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 (
let v' = insert_nat64 (buffer_read b i h) v 1 in
let m = S.update_heap64 (buffer_addr b h + scale16 i + 8) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v' h)
) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem128_hi64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
v: Vale.Def.Types_s.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
(let v' = Vale.Def.Types_s.insert_nat64 (Vale.X64.Memory.buffer_read b i h) v 1 in
let m =
Vale.Arch.MachineHeap_s.update_heap64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i +
8)
v
(Vale.X64.Memory_Sems.get_heap h)
in
Vale.Arch.MachineHeap_s.is_machine_heap_update (Vale.X64.Memory_Sems.get_heap h) m /\
Vale.X64.Memory_Sems.upd_heap h m == Vale.X64.Memory.buffer_write b i v' h)) | {
"end_col": 24,
"end_line": 1122,
"start_col": 2,
"start_line": 1109
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem128_aux
(b: buffer128)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs) | val low_lemma_store_mem128_aux
(b: buffer128)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b)))
let low_lemma_store_mem128_aux
(b: buffer128)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) = | false | null | true | let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs) | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.l_and",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.Memory.buffer_writeable",
"Prims._assert",
"Prims.eq2",
"FStar.Monotonic.HyperStack.mem",
"LowStar.BufferView.Up.upd",
"Vale.Def.Types_s.quad32",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.Interop.Views.up_view128",
"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",
"Prims.unit",
"Vale.X64.BufferViewStore.bv_upd_update_heap128",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.X64.Memory.lemma_store_mem128",
"Vale.X64.Memory.store_mem128",
"Vale.Arch.MachineHeap_s.update_heap128",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale16",
"Vale.Interop.Heap_s.correct_down_p",
"Prims.squash",
"LowStar.BufferView.Down.upd_seq",
"Vale.Interop.get_seq_heap",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem128_aux
(b: buffer128)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem128_aux | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
heap: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h:
Vale.Arch.HeapImpl.vale_heap
{Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.buffer_writeable b}
-> FStar.Pervasives.Lemma
(requires Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h) heap b)
(ensures
(let heap' =
Vale.Arch.MachineHeap_s.update_heap128 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
v
heap
in
let h' =
Vale.X64.Memory.store_mem128 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
v
h
in
InteropHeap?.hs (Vale.Arch.HeapImpl._ih h') ==
LowStar.BufferView.Down.upd_seq (InteropHeap?.hs (Vale.Arch.HeapImpl._ih h))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b))
(Vale.Interop.get_seq_heap heap' (InteropHeap?.addrs (Vale.Arch.HeapImpl._ih h)) b))) | {
"end_col": 57,
"end_line": 792,
"start_col": 115,
"start_line": 783
} |
FStar.Pervasives.Lemma | val written_buffer_down64_aux1
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale8 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end | val written_buffer_down64_aux1
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale8 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k])
let rec written_buffer_down64_aux1
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale8 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) = | false | null | true | if k >= i
then ()
else
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k + 1) h1 mem1 mem2 | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma",
""
] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Vale.X64.Memory_Sems.written_buffer_down64_aux1",
"Prims.unit",
"Vale.X64.Memory_Sems.heap_shift",
"Vale.X64.Memory_Sems.same_mem_get_heap_val64",
"Vale.X64.Memory.scale8",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j])) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val written_buffer_down64_aux1
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale8 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | [
"recursion"
] | Vale.X64.Memory_Sems.written_buffer_down64_aux1 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))} ->
base: Prims.nat{base == Vale.X64.Memory.buffer_addr b h} ->
k: Prims.nat ->
h1: Vale.Arch.HeapImpl.vale_heap{h1 == Vale.X64.Memory.buffer_write b i v h} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h) mem1} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{ Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h1) mem2 /\
(forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) }
-> FStar.Pervasives.Lemma
(ensures
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem1.[ j ]}
j >= base /\ j < base + Vale.X64.Memory.scale8 i ==> mem1.[ j ] == mem2.[ j ])
(decreases i - k) | {
"end_col": 7,
"end_line": 290,
"start_col": 4,
"start_line": 284
} |
FStar.Pervasives.Lemma | val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16))) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 = | false | null | true | let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.l_and",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Vale.X64.Memory.buffer_writeable",
"Prims.eq2",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down_p",
"LowStar.BufferView.Up.length_eq",
"Vale.Interop.Types.base_typ_as_type",
"Prims.unit",
"LowStar.BufferView.Up.put_sel",
"Vale.Interop.Heap_s.hs_of_mem",
"LowStar.BufferView.Up.as_seq_sel",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"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",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16))) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16))) | [] | Vale.X64.Memory_Sems.same_mem_eq_slices128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
h1:
Vale.Arch.HeapImpl.vale_heap
{ FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h1)) /\
Vale.X64.Memory.buffer_writeable b } ->
h2: Vale.Arch.HeapImpl.vale_heap{h2 == Vale.X64.Memory.buffer_write b i v h1} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h1) mem1 b} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h2) mem2 b}
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h1 b) k ==
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h2 b) k)
(ensures
k * 16 + 16 <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) /\
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h1))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 16)
(k * 16 + 16) ==
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h2))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 16)
(k * 16 + 16)) | {
"end_col": 19,
"end_line": 503,
"start_col": 51,
"start_line": 495
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem128_lo64_full (b:buffer128) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i in
let v' = insert_nat64 (buffer_read b i h) v 0 in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v' h) hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
)) | [
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem128_lo64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let v' = insert_nat64 (buffer_read b i hk) v 0 in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v' (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v' hk in
let mhk' = S.update_heap128 ptr v' (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v' h;
low_lemma_store_mem128 b i v' (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v' t;
low_lemma_store_mem128_lo64 b i v h;
low_lemma_valid_mem128_64 b i h;
assert (Map.equal mt (S.update_n (buffer_addr b h + scale16 i) 8 mt t));
() | val low_lemma_store_mem128_lo64_full (b:buffer128) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i in
let v' = insert_nat64 (buffer_read b i h) v 0 in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v' h) hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
))
let low_lemma_store_mem128_lo64_full b i v vfh t hid = | false | null | true | let h, mt, hk = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let v' = insert_nat64 (buffer_read b i hk) v 0 in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v' (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v' hk in
let mhk' = S.update_heap128 ptr v' (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v' h;
low_lemma_store_mem128 b i v' (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v' t;
low_lemma_store_mem128_lo64 b i v h;
low_lemma_valid_mem128_64 b i h;
assert (Map.equal mt (S.update_n (buffer_addr b h + scale16 i) 8 mt t));
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Def.Types_s.nat64",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Map.t",
"Prims.int",
"FStar.Set.equal",
"FStar.Map.domain",
"FStar.Set.complement",
"FStar.Set.empty",
"Prims.unit",
"Prims._assert",
"FStar.Map.equal",
"Vale.X64.Machine_Semantics_s.update_n",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.scale16",
"Vale.X64.Memory_Sems.low_lemma_valid_mem128_64",
"Vale.X64.Memory_Sems.low_lemma_store_mem128_lo64",
"Vale.X64.Memory_Sems.lemma_is_full_update",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.Arch.MachineHeap.same_mem_get_heap_val128",
"Vale.X64.Memory_Sems.in_bounds128",
"Vale.Arch.MachineHeap.frame_update_heap128",
"Vale.X64.Memory_Sems.low_lemma_store_mem128",
"Vale.Lib.Map16.get",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap128",
"Vale.X64.Memory_Sems.get_heap",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Prims.l_Forall",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Map.sel",
"Prims.l_or",
"Vale.Arch.Heap.heap_taint",
"Vale.X64.Memory_Sems.coerce",
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.Heap.heap_get",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.insert_nat64",
"Vale.X64.Memory.buffer_read",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
()
#push-options "--smtencoding.l_arith_repr boxwrap"
let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8)
#pop-options
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
let low_lemma_load_mem128_lo64 b i h =
low_lemma_load_mem128 b i h;
lo64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
let low_lemma_load_mem128_hi64 b i h =
low_lemma_load_mem128 b i h;
hi64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
//let same_domain_update128_64 b i v h =
// low_lemma_valid_mem128_64 b i (_ih h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i) v (get_heap h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i + 8) v (get_heap h)
open Vale.Def.Types_s
let frame_get_heap32 (ptr:int) (mem1 mem2:S.machine_heap) : Lemma
(requires (forall i. i >= ptr /\ i < ptr + 4 ==> mem1.[i] == mem2.[i]))
(ensures S.get_heap_val32 ptr mem1 == S.get_heap_val32 ptr mem2) =
S.get_heap_val32_reveal ()
let update_heap128_lo (ptr:int) (v:quad32) (mem:S.machine_heap) : Lemma
(requires
S.valid_addr128 ptr mem /\
v.hi2 == S.get_heap_val32 (ptr+8) mem /\
v.hi3 == S.get_heap_val32 (ptr+12) mem
)
(ensures S.update_heap128 ptr v mem ==
S.update_heap32 (ptr+4) v.lo1 (S.update_heap32 ptr v.lo0 mem)) =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
S.update_heap128_reveal ();
let mem0 = S.update_heap32 ptr v.lo0 mem in
let mem1 = S.update_heap32 (ptr+4) v.lo1 mem0 in
Vale.Arch.MachineHeap.frame_update_heap32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.frame_update_heap32 (ptr+4) v.lo1 mem0;
Vale.Arch.MachineHeap.same_domain_update32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.same_domain_update32 (ptr+4) v.lo1 mem0;
frame_get_heap32 (ptr+8) mem mem1;
frame_get_heap32 (ptr+12) mem mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+8) mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+12) mem1
let low_lemma_load_mem128_lo_hi_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_valid_mem128_64 b i vfh.vf_heap;
()
let low_lemma_store_mem128_lo64 b i v h =
let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 0 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
S.get_heap_val128_reveal ();
update_heap128_lo ptr v' (get_heap h);
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal () | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem128_lo64_full (b:buffer128) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i in
let v' = insert_nat64 (buffer_read b i h) v 0 in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v' h) hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
)) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem128_lo64_full | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
v: Vale.Def.Types_s.nat64 ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
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 /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h true /\
Vale.X64.Memory.valid_taint_buf128 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let h = Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale16 i in
let v' = Vale.Def.Types_s.insert_nat64 (Vale.X64.Memory.buffer_read b i h) v 0 in
Vale.X64.Memory.buffer_addr b (Mkvale_full_heap?.vf_heap vfh) ==
Vale.X64.Memory.buffer_addr b h /\
Vale.Arch.MachineHeap_s.valid_addr64 ptr
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)) /\
Vale.X64.Memory_Sems.is_full_update vfh
(Vale.X64.Memory.buffer_write b i v' h)
hid
(Vale.Arch.MachineHeap_s.update_heap64 ptr
v
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)))
(Vale.X64.Machine_Semantics_s.update_n ptr
8
(Vale.Arch.Heap.heap_taint (Vale.X64.Memory_Sems.coerce vfh))
t))) | {
"end_col": 4,
"end_line": 1104,
"start_col": 54,
"start_line": 1085
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem128_lo64 (b:buffer128) (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 (
let v' = insert_nat64 (buffer_read b i h) v 0 in
let m = S.update_heap64 (buffer_addr b h + scale16 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v' h
)) | [
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem128_lo64 b i v h =
let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 0 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
S.get_heap_val128_reveal ();
update_heap128_lo ptr v' (get_heap h);
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal () | val low_lemma_store_mem128_lo64 (b:buffer128) (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 (
let v' = insert_nat64 (buffer_read b i h) v 0 in
let m = S.update_heap64 (buffer_addr b h + scale16 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v' h
))
let low_lemma_store_mem128_lo64 b i v h = | false | null | true | let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 0 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
S.get_heap_val128_reveal ();
update_heap128_lo ptr v' (get_heap h);
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal () | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Def.Types_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Def.Types_s.insert_nat64_reveal",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap32_reveal",
"Vale.Arch.MachineHeap_s.update_heap64_reveal",
"Vale.X64.Memory_Sems.update_heap128_lo",
"Vale.X64.Memory_Sems.get_heap",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.X64.Memory_Sems.low_lemma_store_mem128",
"Vale.X64.Memory_Sems.low_lemma_load_mem128",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.insert_nat64",
"Vale.X64.Memory.base_typ_as_vale_type",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.X64.Memory.buffer_read",
"Vale.X64.Memory.vuint128",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale16"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
()
#push-options "--smtencoding.l_arith_repr boxwrap"
let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8)
#pop-options
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
let low_lemma_load_mem128_lo64 b i h =
low_lemma_load_mem128 b i h;
lo64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
let low_lemma_load_mem128_hi64 b i h =
low_lemma_load_mem128 b i h;
hi64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
//let same_domain_update128_64 b i v h =
// low_lemma_valid_mem128_64 b i (_ih h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i) v (get_heap h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i + 8) v (get_heap h)
open Vale.Def.Types_s
let frame_get_heap32 (ptr:int) (mem1 mem2:S.machine_heap) : Lemma
(requires (forall i. i >= ptr /\ i < ptr + 4 ==> mem1.[i] == mem2.[i]))
(ensures S.get_heap_val32 ptr mem1 == S.get_heap_val32 ptr mem2) =
S.get_heap_val32_reveal ()
let update_heap128_lo (ptr:int) (v:quad32) (mem:S.machine_heap) : Lemma
(requires
S.valid_addr128 ptr mem /\
v.hi2 == S.get_heap_val32 (ptr+8) mem /\
v.hi3 == S.get_heap_val32 (ptr+12) mem
)
(ensures S.update_heap128 ptr v mem ==
S.update_heap32 (ptr+4) v.lo1 (S.update_heap32 ptr v.lo0 mem)) =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
S.update_heap128_reveal ();
let mem0 = S.update_heap32 ptr v.lo0 mem in
let mem1 = S.update_heap32 (ptr+4) v.lo1 mem0 in
Vale.Arch.MachineHeap.frame_update_heap32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.frame_update_heap32 (ptr+4) v.lo1 mem0;
Vale.Arch.MachineHeap.same_domain_update32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.same_domain_update32 (ptr+4) v.lo1 mem0;
frame_get_heap32 (ptr+8) mem mem1;
frame_get_heap32 (ptr+12) mem mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+8) mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+12) mem1
let low_lemma_load_mem128_lo_hi_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_valid_mem128_64 b i vfh.vf_heap;
() | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem128_lo64 (b:buffer128) (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 (
let v' = insert_nat64 (buffer_read b i h) v 0 in
let m = S.update_heap64 (buffer_addr b h + scale16 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v' h
)) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem128_lo64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
v: Vale.Def.Types_s.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
(let v' = Vale.Def.Types_s.insert_nat64 (Vale.X64.Memory.buffer_read b i h) v 0 in
let m =
Vale.Arch.MachineHeap_s.update_heap64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
v
(Vale.X64.Memory_Sems.get_heap h)
in
Vale.Arch.MachineHeap_s.is_machine_heap_update (Vale.X64.Memory_Sems.get_heap h) m /\
Vale.X64.Memory_Sems.upd_heap h m == Vale.X64.Memory.buffer_write b i v' h)) | {
"end_col": 24,
"end_line": 1083,
"start_col": 41,
"start_line": 1073
} |
Prims.GTot | val get_heap (h:vale_heap) : GTot (m:S.machine_heap{same_domain h m}) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_heap h = I.down_mem (_ih h) | val get_heap (h:vale_heap) : GTot (m:S.machine_heap{same_domain h m})
let get_heap h = | false | null | false | I.down_mem (_ih h) | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"sometrivial"
] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.down_mem",
"Vale.Arch.HeapImpl._ih",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.X64.Memory_Sems.same_domain"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = () | false | false | Vale.X64.Memory_Sems.fst | {
"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"
} | null | val get_heap (h:vale_heap) : GTot (m:S.machine_heap{same_domain h m}) | [] | Vale.X64.Memory_Sems.get_heap | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot (m: Vale.Arch.MachineHeap_s.machine_heap{Vale.X64.Memory_Sems.same_domain h m}) | {
"end_col": 35,
"end_line": 25,
"start_col": 17,
"start_line": 25
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem128_hi64_full (b:buffer128) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i + 8 in
let v' = insert_nat64 (buffer_read b i h) v 1 in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v' h) hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
)) | [
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem128_hi64_full b i v vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let v' = insert_nat64 (buffer_read b i h) v 1 in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v' (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v' hk in
let mhk' = S.update_heap128 ptr v' (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v' h;
low_lemma_store_mem128 b i v' (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v' t;
low_lemma_store_mem128_hi64 b i v h;
low_lemma_valid_mem128_64 b i h;
assert (Map.equal mt (S.update_n (buffer_addr b h + 16 * i + 8) 8 mt t));
() | val low_lemma_store_mem128_hi64_full (b:buffer128) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i + 8 in
let v' = insert_nat64 (buffer_read b i h) v 1 in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v' h) hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
))
let low_lemma_store_mem128_hi64_full b i v vfh t hid = | false | null | true | reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let h, mt, hk = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let v' = insert_nat64 (buffer_read b i h) v 1 in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v' (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v' hk in
let mhk' = S.update_heap128 ptr v' (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v' h;
low_lemma_store_mem128 b i v' (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v' t;
low_lemma_store_mem128_hi64 b i v h;
low_lemma_valid_mem128_64 b i h;
assert (Map.equal mt (S.update_n (buffer_addr b h + 16 * i + 8) 8 mt t));
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Def.Types_s.nat64",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Map.t",
"Prims.int",
"FStar.Set.equal",
"FStar.Map.domain",
"FStar.Set.complement",
"FStar.Set.empty",
"Prims.unit",
"Prims._assert",
"FStar.Map.equal",
"Vale.X64.Machine_Semantics_s.update_n",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"FStar.Mul.op_Star",
"Vale.X64.Memory_Sems.low_lemma_valid_mem128_64",
"Vale.X64.Memory_Sems.low_lemma_store_mem128_hi64",
"Vale.X64.Memory_Sems.lemma_is_full_update",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.Arch.MachineHeap.same_mem_get_heap_val128",
"Vale.X64.Memory_Sems.in_bounds128",
"Vale.Arch.MachineHeap.frame_update_heap128",
"Vale.X64.Memory_Sems.low_lemma_store_mem128",
"Vale.Lib.Map16.get",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap128",
"Vale.X64.Memory_Sems.get_heap",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Prims.l_Forall",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Map.sel",
"Prims.l_or",
"Vale.Arch.Heap.heap_taint",
"Vale.X64.Memory_Sems.coerce",
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Memory.scale16",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.insert_nat64",
"Vale.X64.Memory.buffer_read",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
()
#push-options "--smtencoding.l_arith_repr boxwrap"
let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8)
#pop-options
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
let low_lemma_load_mem128_lo64 b i h =
low_lemma_load_mem128 b i h;
lo64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
let low_lemma_load_mem128_hi64 b i h =
low_lemma_load_mem128 b i h;
hi64_reveal ();
S.get_heap_val128_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val32_reveal ()
//let same_domain_update128_64 b i v h =
// low_lemma_valid_mem128_64 b i (_ih h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i) v (get_heap h);
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale16 i + 8) v (get_heap h)
open Vale.Def.Types_s
let frame_get_heap32 (ptr:int) (mem1 mem2:S.machine_heap) : Lemma
(requires (forall i. i >= ptr /\ i < ptr + 4 ==> mem1.[i] == mem2.[i]))
(ensures S.get_heap_val32 ptr mem1 == S.get_heap_val32 ptr mem2) =
S.get_heap_val32_reveal ()
let update_heap128_lo (ptr:int) (v:quad32) (mem:S.machine_heap) : Lemma
(requires
S.valid_addr128 ptr mem /\
v.hi2 == S.get_heap_val32 (ptr+8) mem /\
v.hi3 == S.get_heap_val32 (ptr+12) mem
)
(ensures S.update_heap128 ptr v mem ==
S.update_heap32 (ptr+4) v.lo1 (S.update_heap32 ptr v.lo0 mem)) =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
S.update_heap128_reveal ();
let mem0 = S.update_heap32 ptr v.lo0 mem in
let mem1 = S.update_heap32 (ptr+4) v.lo1 mem0 in
Vale.Arch.MachineHeap.frame_update_heap32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.frame_update_heap32 (ptr+4) v.lo1 mem0;
Vale.Arch.MachineHeap.same_domain_update32 ptr v.lo0 mem;
Vale.Arch.MachineHeap.same_domain_update32 (ptr+4) v.lo1 mem0;
frame_get_heap32 (ptr+8) mem mem1;
frame_get_heap32 (ptr+12) mem mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+8) mem1;
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+12) mem1
let low_lemma_load_mem128_lo_hi_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_valid_mem128_64 b i vfh.vf_heap;
()
let low_lemma_store_mem128_lo64 b i v h =
let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 0 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
S.get_heap_val128_reveal ();
update_heap128_lo ptr v' (get_heap h);
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal ()
let low_lemma_store_mem128_lo64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let v' = insert_nat64 (buffer_read b i hk) v 0 in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v' (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v' hk in
let mhk' = S.update_heap128 ptr v' (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v' h;
low_lemma_store_mem128 b i v' (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v' hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v' t;
low_lemma_store_mem128_lo64 b i v h;
low_lemma_valid_mem128_64 b i h;
assert (Map.equal mt (S.update_n (buffer_addr b h + scale16 i) 8 mt t));
()
#push-options "--z3rlimit 20 --using_facts_from '* -LowStar.Monotonic.Buffer.loc_disjoint_includes_r'"
#restart-solver
let low_lemma_store_mem128_hi64 b i v h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
let ptr = buffer_addr b h + scale16 i in
let v128 = buffer_read b i h in
let v' = insert_nat64 v128 v 1 in
low_lemma_load_mem128 b i h;
low_lemma_store_mem128 b i v' h;
assert (S.valid_addr128 ptr (get_heap h));
Vale.Arch.MachineHeap.update_heap32_get_heap32 ptr (get_heap h);
Vale.Arch.MachineHeap.update_heap32_get_heap32 (ptr+4) (get_heap h);
S.get_heap_val128_reveal ();
S.update_heap128_reveal ();
S.update_heap64_reveal ();
S.update_heap32_reveal ();
insert_nat64_reveal ()
#pop-options | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem128_hi64_full (b:buffer128) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i + 8 in
let v' = insert_nat64 (buffer_read b i h) v 1 in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v' h) hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
)) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem128_hi64_full | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
v: Vale.Def.Types_s.nat64 ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
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 /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h true /\
Vale.X64.Memory.valid_taint_buf128 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let h = Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale16 i + 8 in
let v' = Vale.Def.Types_s.insert_nat64 (Vale.X64.Memory.buffer_read b i h) v 1 in
Vale.X64.Memory.buffer_addr b (Mkvale_full_heap?.vf_heap vfh) ==
Vale.X64.Memory.buffer_addr b h /\
Vale.Arch.MachineHeap_s.valid_addr64 ptr
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)) /\
Vale.X64.Memory_Sems.is_full_update vfh
(Vale.X64.Memory.buffer_write b i v' h)
hid
(Vale.Arch.MachineHeap_s.update_heap64 ptr
v
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)))
(Vale.X64.Machine_Semantics_s.update_n ptr
8
(Vale.Arch.Heap.heap_taint (Vale.X64.Memory_Sems.coerce vfh))
t))) | {
"end_col": 4,
"end_line": 1145,
"start_col": 2,
"start_line": 1126
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem64_full (b:buffer64) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf64 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let h' = buffer_write b i v h in
let ptr = buffer_addr b h + scale8 i in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh h' hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
() | val low_lemma_store_mem64_full (b:buffer64) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf64 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let h' = buffer_write b i v h in
let ptr = buffer_addr b h + scale8 i in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh h' hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
))
let low_lemma_store_mem64_full b i v vfh t hid = | false | null | true | let h, mt, hk = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer64",
"Prims.nat",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.memtaint",
"Prims.unit",
"Vale.X64.Memory_Sems.lemma_is_full_update",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.Arch.MachineHeap.same_mem_get_heap_val64",
"Vale.X64.Memory_Sems.in_bounds64",
"Vale.Arch.MachineHeap.frame_update_heap64",
"Vale.X64.Memory_Sems.low_lemma_store_mem64",
"Vale.Lib.Map16.get",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap64",
"Vale.X64.Memory_Sems.get_heap",
"Vale.X64.Memory.buffer_write",
"Vale.X64.Memory.vuint64",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Prims.l_Forall",
"Prims.int",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.eq2",
"FStar.Map.sel",
"Prims.l_or",
"Vale.Arch.Heap.heap_taint",
"Vale.X64.Machine_Semantics_s.update_n",
"Vale.X64.Memory_Sems.coerce",
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale8",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
() | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem64_full (b:buffer64) (i:nat) (v:nat64) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf64 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let h' = buffer_write b i v h in
let ptr = buffer_addr b h + scale8 i in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr64 ptr (heap_get (coerce vfh)) /\
is_full_update vfh h' hid
(S.update_heap64 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 8 (heap_taint (coerce vfh)) t)
)) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem64_full | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64 ->
i: Prims.nat ->
v: Vale.Def.Words_s.nat64 ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
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 /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h true /\
Vale.X64.Memory.valid_taint_buf64 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let h = Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid in
let h' = Vale.X64.Memory.buffer_write b i v h in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale8 i in
Vale.X64.Memory.buffer_addr b (Mkvale_full_heap?.vf_heap vfh) ==
Vale.X64.Memory.buffer_addr b h /\
Vale.Arch.MachineHeap_s.valid_addr64 ptr
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)) /\
Vale.X64.Memory_Sems.is_full_update vfh
h'
hid
(Vale.Arch.MachineHeap_s.update_heap64 ptr
v
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)))
(Vale.X64.Machine_Semantics_s.update_n ptr
8
(Vale.Arch.Heap.heap_taint (Vale.X64.Memory_Sems.coerce vfh))
t))) | {
"end_col": 4,
"end_line": 722,
"start_col": 48,
"start_line": 707
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem64_aux
(b: buffer64)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs) | val low_lemma_store_mem64_aux
(b: buffer64)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b)))
let low_lemma_store_mem64_aux
(b: buffer64)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) = | false | null | true | let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs) | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer64",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint64",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.l_and",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.Memory.buffer_writeable",
"Prims._assert",
"Prims.eq2",
"FStar.Monotonic.HyperStack.mem",
"LowStar.BufferView.Up.upd",
"FStar.UInt64.t",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"FStar.UInt64.uint_to_t",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.Interop.Views.up_view64",
"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",
"Prims.unit",
"Vale.X64.BufferViewStore.bv_upd_update_heap64",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.X64.Memory.lemma_store_mem64",
"Vale.X64.Memory.store_mem64",
"Vale.Arch.MachineHeap_s.update_heap64",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale8",
"Vale.Interop.Heap_s.correct_down_p",
"Prims.squash",
"LowStar.BufferView.Down.upd_seq",
"Vale.Interop.get_seq_heap",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem64_aux
(b: buffer64)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem64_aux | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64 ->
heap: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h:
Vale.Arch.HeapImpl.vale_heap
{Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.buffer_writeable b}
-> FStar.Pervasives.Lemma
(requires Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h) heap b)
(ensures
(let heap' =
Vale.Arch.MachineHeap_s.update_heap64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale8 i)
v
heap
in
let h' =
Vale.X64.Memory.store_mem64 (Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale8 i)
v
h
in
InteropHeap?.hs (Vale.Arch.HeapImpl._ih h') ==
LowStar.BufferView.Down.upd_seq (InteropHeap?.hs (Vale.Arch.HeapImpl._ih h))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b))
(Vale.Interop.get_seq_heap heap' (InteropHeap?.addrs (Vale.Arch.HeapImpl._ih h)) b))) | {
"end_col": 76,
"end_line": 607,
"start_col": 115,
"start_line": 598
} |
FStar.Pervasives.Lemma | val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i])) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)]) | val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
let heap_shift m1 m2 base n = | false | null | true | assert (forall i. base <= i /\ i < base + n ==> m1.[ base + (i - base) ] == m2.[ base + (i - base) ]
) | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.int",
"Prims.nat",
"Prims._assert",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap" | false | false | Vale.X64.Memory_Sems.fst | {
"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": "boxwrap",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i])) | [] | Vale.X64.Memory_Sems.heap_shift | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
m1: Vale.Arch.MachineHeap_s.machine_heap ->
m2: Vale.Arch.MachineHeap_s.machine_heap ->
base: Prims.int ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires forall (i: Prims.int). 0 <= i /\ i < n ==> m1.[ base + i ] == m2.[ base + i ])
(ensures
forall (i: Prims.int). {:pattern m1.[ i ]}
base <= i /\ i < base + n ==> m1.[ i ] == m2.[ i ]) | {
"end_col": 53,
"end_line": 201,
"start_col": 2,
"start_line": 200
} |
FStar.Pervasives.Lemma | val unwritten_buffer_down
(t: base_typ)
(b: buffer t {buffer_writeable b})
(i: nat{i < buffer_length b})
(v: base_typ_as_vale_type t)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a: b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j.
{:pattern
mem1.[ j ]; List.memP a (IB.ptrs_of_mem (_ih h))\/mem2.[ j ];
List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux | val unwritten_buffer_down
(t: base_typ)
(b: buffer t {buffer_writeable b})
(i: nat{i < buffer_length b})
(v: base_typ_as_vale_type t)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a: b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j.
{:pattern
mem1.[ j ]; List.memP a (IB.ptrs_of_mem (_ih h))\/mem2.[ j ];
List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ]))
let unwritten_buffer_down
(t: base_typ)
(b: buffer t {buffer_writeable b})
(i: nat{i < buffer_length b})
(v: base_typ_as_vale_type t)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a: b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j.
{:pattern
mem1.[ j ]; List.memP a (IB.ptrs_of_mem (_ih h))\/mem2.[ j ];
List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) = | false | null | true | let aux (a: b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) =
let db = get_downview a.bsrc in
if DV.length db = 0
then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq)
IB.list_disjoint_or_eq
IB.list_disjoint_or_eq_def
(MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j: int). {:pattern (mem1.[ j ])}
base <= j /\ j < base + Seq.length s0 ==>
v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[ j ]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.buffer_writeable",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.base_typ_as_vale_type",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"FStar.Classical.forall_intro",
"Vale.X64.Memory.b8",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2",
"Prims.l_Forall",
"Prims.int",
"Prims.l_imp",
"Prims.op_GreaterThanOrEqual",
"Vale.Interop.Heap_s.addrs_of_mem",
"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",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Memory_Sems.heap_shift",
"Prims._assert",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.l_or",
"Vale.Def.Words_s.pow2_8",
"Vale.X64.Memory.v_to_typ",
"Vale.Arch.HeapTypes_s.TUInt8",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"FStar.Seq.Base.equal",
"Vale.Lib.BufferViewHelpers.lemma_dv_equal",
"Vale.Interop.Types.down_view",
"Vale.Interop.Heap_s.hs_of_mem",
"Vale.Def.Opaque_s.opaque_assert",
"Prims.list",
"Prims.logical",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Vale.Interop.Heap_s.list_disjoint_or_eq_def",
"LowStar.Monotonic.Buffer.disjoint",
"FStar.Seq.Properties.lseq",
"LowStar.BufferView.Down.as_seq",
"Vale.Def.Words_s.nat64",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"LowStar.BufferView.Down.buffer"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val unwritten_buffer_down
(t: base_typ)
(b: buffer t {buffer_writeable b})
(i: nat{i < buffer_length b})
(v: base_typ_as_vale_type t)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a: b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j.
{:pattern
mem1.[ j ]; List.memP a (IB.ptrs_of_mem (_ih h))\/mem2.[ j ];
List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) | [] | Vale.X64.Memory_Sems.unwritten_buffer_down | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.Arch.HeapImpl.buffer t {Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.base_typ_as_vale_type t ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
forall (a:
Vale.X64.Memory.b8
{ FStar.List.Tot.Base.memP a
(Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h)) /\ ~(a == b) })
(j: Prims.int).
{:pattern
mem1.[ j ];
FStar.List.Tot.Base.memP a (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))\/mem2.[
j ];
FStar.List.Tot.Base.memP a (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))}
let base = Vale.Interop.Heap_s.addrs_of_mem (Vale.Arch.HeapImpl._ih h) a in
j >= base /\
j <
base + LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc a)) ==>
mem1.[ j ] == mem2.[ j ])) | {
"end_col": 30,
"end_line": 377,
"start_col": 3,
"start_line": 351
} |
FStar.Pervasives.Lemma | val equiv_load_mem128 (ptr:int) (m:vale_heap) : Lemma
(requires valid_mem128 ptr m)
(ensures load_mem128 ptr m == S.get_heap_val128 ptr (get_heap m)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h | val equiv_load_mem128 (ptr:int) (m:vale_heap) : Lemma
(requires valid_mem128 ptr m)
(ensures load_mem128 ptr m == S.get_heap_val128 ptr (get_heap m))
let equiv_load_mem128 ptr h = | false | null | true | equiv_load_mem128_aux ptr h | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory_Sems.equiv_load_mem128_aux",
"Prims.unit"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val equiv_load_mem128 (ptr:int) (m:vale_heap) : Lemma
(requires valid_mem128 ptr m)
(ensures load_mem128 ptr m == S.get_heap_val128 ptr (get_heap m)) | [] | Vale.X64.Memory_Sems.equiv_load_mem128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> m: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem128 ptr m)
(ensures
Vale.X64.Memory.load_mem128 ptr m ==
Vale.Arch.MachineHeap_s.get_heap_val128 ptr (Vale.X64.Memory_Sems.get_heap m)) | {
"end_col": 29,
"end_line": 753,
"start_col": 2,
"start_line": 753
} |
FStar.Pervasives.Lemma | val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x])) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i) | val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 = | false | null | true | let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x: int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[ x ] == mem2.[ x ]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[ addr + (scale8 k + i) ] ==
UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[ addr + (scale8 k + i) ] ==
UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i) | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down_p",
"Prims._assert",
"Prims.l_Forall",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt8.n",
"Prims.op_GreaterThanOrEqual",
"Vale.Def.Words_s.pow2_8",
"FStar.UInt8.v",
"FStar.Seq.Base.index",
"FStar.UInt8.t",
"LowStar.BufferView.Down.as_seq",
"Vale.Interop.Heap_s.hs_of_mem",
"FStar.Mul.op_Star",
"Vale.X64.Memory_Sems.length_up64",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"Vale.X64.Memory_Sems.same_mem_eq_slices64",
"LowStar.BufferView.Up.as_seq_sel",
"FStar.UInt64.t",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"Vale.X64.Memory.uint64_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.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.op_Subtraction",
"Vale.X64.Memory.buffer_addr"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x])) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x])) | [] | Vale.X64.Memory_Sems.same_mem_get_heap_val64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
h1:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h1))} ->
h2: Vale.Arch.HeapImpl.vale_heap{h2 == Vale.X64.Memory.buffer_write b i v h1} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h1) mem1 b} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h2) mem2 b}
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h1 b) k ==
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h2 b) k)
(ensures
(let ptr = Vale.X64.Memory.buffer_addr b h1 + Vale.X64.Memory.scale8 k in
forall (x: Prims.int). {:pattern mem1.[ x ]}
ptr <= x /\ x < ptr + 8 ==> mem1.[ x ] == mem2.[ x ])) | {
"end_col": 53,
"end_line": 265,
"start_col": 53,
"start_line": 245
} |
FStar.Pervasives.Lemma | val lemma_make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat)
: Lemma
(requires
n <= Seq.length bs /\
(forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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)))
(ensures
(let m, s = make_owns h bs n in
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (s i)}
(Set.mem a (s i) <==>
Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==>
buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))) /\
(forall (k: nat) (a: int). {:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==>
Set.mem a (s (Seq.index bs k).bi_heaplet)))) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
() | val lemma_make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat)
: Lemma
(requires
n <= Seq.length bs /\
(forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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)))
(ensures
(let m, s = make_owns h bs n in
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (s i)}
(Set.mem a (s i) <==>
Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==>
buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))) /\
(forall (k: nat) (a: int). {:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==>
Set.mem a (s (Seq.index bs k).bi_heaplet))))
let rec lemma_make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat)
: Lemma
(requires
n <= Seq.length bs /\
(forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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)))
(ensures
(let m, s = make_owns h bs n in
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (s i)}
(Set.mem a (s i) <==>
Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==>
buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))) /\
(forall (k: nat) (a: int). {:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==>
Set.mem a (s (Seq.index bs k).bi_heaplet)))) = | false | null | true | reveal_opaque (`%make_owns) make_owns;
if n = 0
then ()
else
let _ = make_owns h bs (n - 1) in
let m, s = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a: int)
: Lemma (requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))] =
I.addrs_set_mem h.ih b a
in
let lem2 (i: heaplet_id) (a: int)
: Lemma (requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))] =
reveal_opaque (`%addr_map_pred) addr_map_pred
in
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Pervasives.Native.option",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Arch.HeapImpl.heaplet_id",
"FStar.Set.set",
"Prims.unit",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2",
"FStar.Set.mem",
"FStar.Set.intersect",
"Prims.squash",
"Prims.l_False",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"FStar.Pervasives.reveal_opaque",
"Vale.Interop.Types.b8",
"Vale.Def.Words_s.nat64",
"Prims.logical",
"Vale.Interop.Types.addr_map_pred",
"FStar.Map.domain",
"Vale.Def.Words_s.nat8",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Interop.addrs_set_mem",
"FStar.Ghost.reveal",
"Vale.Interop.Heap_s.interop_heap",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__ih",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory_Sems.set_of_range",
"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.Heap_s.global_addrs_map",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"Vale.Arch.HeapImpl.buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"Vale.X64.Memory_Sems.lemma_make_owns",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Memory_Sems.make_owns",
"Prims.op_LessThanOrEqual",
"Prims.l_Forall",
"Prims.l_imp",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.Memory.buffer_info_disjoint",
"Prims.l_iff",
"FStar.Option.mapTot",
"FStar.Pervasives.Native.Some",
"Vale.X64.Memory_Sems.buffer_info_has_addr_opt",
"Vale.X64.Memory_Sems.buffer_info_has_addr"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
)) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat)
: Lemma
(requires
n <= Seq.length bs /\
(forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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)))
(ensures
(let m, s = make_owns h bs n in
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (s i)}
(Set.mem a (s i) <==>
Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==>
buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))) /\
(forall (k: nat) (a: int). {:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==>
Set.mem a (s (Seq.index bs k).bi_heaplet)))) | [
"recursion"
] | Vale.X64.Memory_Sems.lemma_make_owns | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
h: Vale.Arch.HeapImpl.vale_heap ->
bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= FStar.Seq.Base.length bs /\
(forall (i: Prims.nat). {:pattern FStar.Seq.Base.index bs i}
i < FStar.Seq.Base.length bs ==>
Vale.X64.Memory.buffer_readable h (Mkbuffer_info?.bi_buffer (FStar.Seq.Base.index bs i))
) /\
(forall (i1: Prims.nat) (i2: Prims.nat).
{:pattern FStar.Seq.Base.index bs i1; FStar.Seq.Base.index bs i2}
i1 < FStar.Seq.Base.length bs /\ i2 < FStar.Seq.Base.length bs ==>
Vale.X64.Memory.buffer_info_disjoint (FStar.Seq.Base.index bs i1)
(FStar.Seq.Base.index bs i2)))
(ensures
(let _ = Vale.X64.Memory_Sems.make_owns h bs n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ m s = _ in
(forall (i: Vale.Arch.HeapImpl.heaplet_id) (a: Prims.int).
{:pattern FStar.Set.mem a (s i)}
(FStar.Set.mem a (s i) <==>
FStar.Option.mapTot (fun n ->
Mkbuffer_info?.bi_heaplet (FStar.Seq.Base.index bs n))
(m a) ==
FStar.Pervasives.Native.Some i) /\
(FStar.Set.mem a (s i) ==>
Vale.X64.Memory_Sems.buffer_info_has_addr_opt (FStar.Option.mapTot (fun n ->
FStar.Seq.Base.index bs n)
(m a))
a) /\
(FStar.Set.mem a (s i) ==> FStar.Set.mem a (FStar.Map.domain (ValeHeap?.mh h)))) /\
(forall (k: Prims.nat) (a: Prims.int).
{:pattern
FStar.Set.mem a (s (Mkbuffer_info?.bi_heaplet (FStar.Seq.Base.index bs k)))}
k < n /\ Vale.X64.Memory_Sems.buffer_info_has_addr (FStar.Seq.Base.index bs k) a ==>
FStar.Set.mem a (s (Mkbuffer_info?.bi_heaplet (FStar.Seq.Base.index bs k)))))
<:
Type0)) | {
"end_col": 4,
"end_line": 124,
"start_col": 2,
"start_line": 99
} |
FStar.Pervasives.Lemma | val length_up64 (b: buffer64) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 8})
: Lemma (scale8 k + i <= DV.length (get_downview b.bsrc)) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb | val length_up64 (b: buffer64) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 8})
: Lemma (scale8 k + i <= DV.length (get_downview b.bsrc))
let length_up64 (b: buffer64) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 8})
: Lemma (scale8 k + i <= DV.length (get_downview b.bsrc)) = | false | null | true | let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint64",
"LowStar.BufferView.Up.length_eq",
"FStar.UInt64.t",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.X64.Memory.uint64_view",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_up64 (b: buffer64) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 8})
: Lemma (scale8 k + i <= DV.length (get_downview b.bsrc)) | [] | Vale.X64.Memory_Sems.length_up64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64 ->
h: Vale.Arch.HeapImpl.vale_heap ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
i: Prims.nat{i < 8}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Memory.scale8 k + i <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) | {
"end_col": 17,
"end_line": 231,
"start_col": 53,
"start_line": 229
} |
FStar.Pervasives.Lemma | val in_bounds64 (h: vale_heap) (b: buffer64) (i: nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc)) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b | val in_bounds64 (h: vale_heap) (b: buffer64) (i: nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
let in_bounds64 (h: vale_heap) (b: buffer64) (i: nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc)) = | false | null | true | length_t_eq TUInt64 b | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.buffer64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint64",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"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.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc)) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val in_bounds64 (h: vale_heap) (b: buffer64) (i: nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc)) | [] | Vale.X64.Memory_Sems.in_bounds64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
h: Vale.Arch.HeapImpl.vale_heap ->
b: Vale.X64.Memory.buffer64 ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Memory.scale8 i + 8 <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) | {
"end_col": 23,
"end_line": 452,
"start_col": 2,
"start_line": 452
} |
FStar.Pervasives.Lemma | val length_up128 (b: buffer128) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 16})
: Lemma (scale16 k + i <= DV.length (get_downview b.bsrc)) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb | val length_up128 (b: buffer128) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 16})
: Lemma (scale16 k + i <= DV.length (get_downview b.bsrc))
let length_up128 (b: buffer128) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 16})
: Lemma (scale16 k + i <= DV.length (get_downview b.bsrc)) = | false | null | true | let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"LowStar.BufferView.Up.length_eq",
"Vale.Def.Types_s.quad32",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.X64.Memory.uint128_view",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale16",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_up128 (b: buffer128) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 16})
: Lemma (scale16 k + i <= DV.length (get_downview b.bsrc)) | [] | Vale.X64.Memory_Sems.length_up128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
h: Vale.Arch.HeapImpl.vale_heap ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
i: Prims.nat{i < 16}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Memory.scale16 k + i <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) | {
"end_col": 17,
"end_line": 508,
"start_col": 54,
"start_line": 506
} |
FStar.Pervasives.Lemma | val bytes_valid64 (i:int) (m:vale_heap) : Lemma
(requires valid_mem64 i m)
(ensures S.valid_addr64 i (get_heap m))
[SMTPat (S.valid_addr64 i (get_heap m))] | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7) | val bytes_valid64 (i:int) (m:vale_heap) : Lemma
(requires valid_mem64 i m)
(ensures S.valid_addr64 i (get_heap m))
[SMTPat (S.valid_addr64 i (get_heap m))]
let bytes_valid64 ptr h = | false | null | true | reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr + 1);
I.addrs_set_mem (_ih h) b (ptr + 2);
I.addrs_set_mem (_ih h) b (ptr + 3);
I.addrs_set_mem (_ih h) b (ptr + 4);
I.addrs_set_mem (_ih h) b (ptr + 5);
I.addrs_set_mem (_ih h) b (ptr + 6);
I.addrs_set_mem (_ih h) b (ptr + 7) | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.addrs_set_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.op_Addition",
"Prims.unit",
"Vale.X64.Memory_Sems.in_bounds64",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.get_addr_ptr",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr64"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bytes_valid64 (i:int) (m:vale_heap) : Lemma
(requires valid_mem64 i m)
(ensures S.valid_addr64 i (get_heap m))
[SMTPat (S.valid_addr64 i (get_heap m))] | [] | Vale.X64.Memory_Sems.bytes_valid64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | i: Prims.int -> m: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem64 i m)
(ensures Vale.Arch.MachineHeap_s.valid_addr64 i (Vale.X64.Memory_Sems.get_heap m))
[SMTPat (Vale.Arch.MachineHeap_s.valid_addr64 i (Vale.X64.Memory_Sems.get_heap m))] | {
"end_col": 36,
"end_line": 467,
"start_col": 2,
"start_line": 455
} |
FStar.Pervasives.Lemma | val low_lemma_valid_mem128_64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr64 (buffer_addr b h + scale16 i) (get_heap h) /\
S.valid_addr64 (buffer_addr b h + scale16 i + 8) (get_heap h)
) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8) | val low_lemma_valid_mem128_64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr64 (buffer_addr b h + scale16 i) (get_heap h) /\
S.valid_addr64 (buffer_addr b h + scale16 i + 8) (get_heap h)
)
let low_lemma_valid_mem128_64 b i h = | false | null | true | reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8) | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_heap",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.scale16",
"Prims.unit",
"Vale.X64.Memory_Sems.low_lemma_valid_mem128",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.Arch.MachineHeap_s.valid_addr64"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
()
#push-options "--smtencoding.l_arith_repr boxwrap" | false | false | Vale.X64.Memory_Sems.fst | {
"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": "boxwrap",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_valid_mem128_64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr64 (buffer_addr b h + scale16 i) (get_heap h) /\
S.valid_addr64 (buffer_addr b h + scale16 i + 8) (get_heap h)
) | [] | Vale.X64.Memory_Sems.low_lemma_valid_mem128_64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.X64.Memory.buffer128 -> i: Prims.nat -> 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)
(ensures
Vale.Arch.MachineHeap_s.valid_addr64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
(Vale.X64.Memory_Sems.get_heap h) /\
Vale.Arch.MachineHeap_s.valid_addr64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i +
8)
(Vale.X64.Memory_Sems.get_heap h)) | {
"end_col": 52,
"end_line": 1015,
"start_col": 2,
"start_line": 1011
} |
FStar.Pervasives.Lemma | val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2 | val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h = | false | null | true | let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[ j ] == mem2.[ j ]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in
aux ();
aux2 ();
Map.lemma_equal_intro mem1 mem2 | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Map.lemma_equal_intro",
"Prims.int",
"Vale.Def.Types_s.nat8",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Words_s.nat8",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Vale.Arch.MachineHeap.same_domain_update64",
"Vale.X64.Memory_Sems.bytes_valid64",
"Prims.l_Forall",
"Prims.eq2",
"FStar.Map.sel",
"Vale.Arch.MachineHeap.frame_update_heap64",
"Vale.Arch.MachineHeap.correct_update_get64",
"Vale.Arch.MachineHeap.same_mem_get_heap_val64",
"Vale.X64.Memory.op_String_Access",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory_Sems.store_buffer_aux_down64_mem2",
"Vale.X64.Memory_Sems.store_buffer_aux_down64_mem",
"Vale.X64.Memory.store_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.Arch.MachineHeap_s.update_heap64",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
)) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
)) | [] | Vale.X64.Memory_Sems.valid_state_store_mem64_aux | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | i: Prims.nat -> v: Vale.Def.Words_s.nat64 -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.writeable_mem64 i h)
(ensures
(let heap = Vale.X64.Memory_Sems.get_heap h in
let heap' = Vale.Arch.MachineHeap_s.update_heap64 i v heap in
let h' = Vale.X64.Memory.store_mem64 i v h in
heap' == Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h'))) | {
"end_col": 33,
"end_line": 634,
"start_col": 39,
"start_line": 618
} |
FStar.Pervasives.Lemma | val store_buffer_aux_down128_mem (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 16 ==> mem1.[ j ] == mem2.[ j ])) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h | val store_buffer_aux_down128_mem (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 16 ==> mem1.[ j ] == mem2.[ j ]))
let store_buffer_aux_down128_mem (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 16 ==> mem1.[ j ] == mem2.[ j ])) = | false | null | true | let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i + 1) == ptr + 16);
store_buffer_down128_mem b i v h | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.b2t",
"Vale.X64.Memory.writeable_mem128",
"Vale.X64.Memory_Sems.store_buffer_down128_mem",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale16",
"Vale.X64.Memory.store_buffer_write",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapImpl.buffer",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.find_writeable_buffer",
"Vale.X64.Memory.store_mem",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt128",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==> | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_buffer_aux_down128_mem (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 16 ==> mem1.[ j ] == mem2.[ j ])) | [] | Vale.X64.Memory_Sems.store_buffer_aux_down128_mem | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ptr: Prims.int ->
v: Vale.X64.Memory.quad32 ->
h: Vale.Arch.HeapImpl.vale_heap{Vale.X64.Memory.writeable_mem128 ptr h}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.store_mem Vale.Arch.HeapTypes_s.TUInt128 ptr v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 16 ==> mem1.[ j ] == mem2.[ j ])) | {
"end_col": 36,
"end_line": 929,
"start_col": 3,
"start_line": 921
} |
FStar.Pervasives.Lemma | val store_buffer_down128_mem
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux | val store_buffer_down128_mem
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ]))
let store_buffer_down128_mem
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) = | false | null | true | let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j: int)
: Lemma (j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ]) =
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc)
then
(written_buffer_down128 b i v h;
length_t_eq TUInt128 b)
else
if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"FStar.Classical.forall_intro",
"Prims.int",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_Addition",
"Vale.X64.Memory.scale16",
"Prims.op_GreaterThanOrEqual",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.X64.Memory.scale_by",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_AmpAmp",
"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.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.X64.Memory_Sems.written_buffer_down128",
"Prims.bool",
"Prims.op_Negation",
"Vale.Interop.valid_addr",
"Vale.Interop.same_unspecified_down",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.X64.Memory_Sems.unwritten_buffer_down",
"Vale.Interop.addrs_set_lemma_all",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Prims.l_Forall"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==> | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_buffer_down128_mem
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | [] | Vale.X64.Memory_Sems.store_buffer_down128_mem | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h))}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
let base = Vale.X64.Memory.buffer_addr b h in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + Vale.X64.Memory.scale16 i \/ j >= base + Vale.X64.Memory.scale16 (i + 1) ==>
mem1.[ j ] == mem2.[ j ])) | {
"end_col": 30,
"end_line": 910,
"start_col": 3,
"start_line": 891
} |
FStar.Pervasives.Lemma | val store_buffer_aux_down128_mem2 (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour (S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr + 4) mem2)
(S.get_heap_val32 (ptr + 8) mem2)
(S.get_heap_val32 (ptr + 12) mem2) ==
v)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i | val store_buffer_aux_down128_mem2 (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour (S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr + 4) mem2)
(S.get_heap_val32 (ptr + 8) mem2)
(S.get_heap_val32 (ptr + 12) mem2) ==
v))
let store_buffer_aux_down128_mem2 (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour (S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr + 4) mem2)
(S.get_heap_val32 (ptr + 8) mem2)
(S.get_heap_val32 (ptr + 12) mem2) ==
v)) = | false | null | true | let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.b2t",
"Vale.X64.Memory.writeable_mem128",
"Vale.X64.Memory.index128_get_heap_val128",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.X64.Memory.base_typ_as_vale_type",
"FStar.Seq.Base.index",
"Vale.X64.Memory.buffer_as_seq",
"Vale.X64.Memory.store_buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory.store_mem",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapImpl.buffer",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.find_writeable_buffer",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt128",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words_s.four",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.Mkfour",
"Vale.Arch.MachineHeap_s.get_heap_val32",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_buffer_aux_down128_mem2 (ptr: int) (v: quad32) (h: vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures
(let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour (S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr + 4) mem2)
(S.get_heap_val32 (ptr + 8) mem2)
(S.get_heap_val32 (ptr + 12) mem2) ==
v)) | [] | Vale.X64.Memory_Sems.store_buffer_aux_down128_mem2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ptr: Prims.int ->
v: Vale.X64.Memory.quad32 ->
h: Vale.Arch.HeapImpl.vale_heap{Vale.X64.Memory.writeable_mem128 ptr h}
-> FStar.Pervasives.Lemma
(ensures
(let h1 = Vale.X64.Memory.store_mem Vale.Arch.HeapTypes_s.TUInt128 ptr v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
Vale.Def.Words_s.Mkfour (Vale.Arch.MachineHeap_s.get_heap_val32 ptr mem2)
(Vale.Arch.MachineHeap_s.get_heap_val32 (ptr + 4) mem2)
(Vale.Arch.MachineHeap_s.get_heap_val32 (ptr + 8) mem2)
(Vale.Arch.MachineHeap_s.get_heap_val32 (ptr + 12) mem2) ==
v)) | {
"end_col": 40,
"end_line": 950,
"start_col": 16,
"start_line": 941
} |
FStar.Pervasives.Lemma | val written_buffer_down64_aux2
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale8 (i + 1) <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale8 (i + 1) /\ j < base + scale8 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end | val written_buffer_down64_aux2
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale8 (i + 1) <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale8 (i + 1) /\ j < base + scale8 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k])
let rec written_buffer_down64_aux2
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale8 (i + 1) <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale8 (i + 1) /\ j < base + scale8 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) = | false | null | true | if k >= n
then ()
else
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k + 1) h1 mem1 mem2 | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma",
""
] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Prims.op_GreaterThan",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"FStar.Mul.op_Star",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Vale.X64.Memory_Sems.written_buffer_down64_aux2",
"Prims.unit",
"Vale.X64.Memory_Sems.heap_shift",
"Vale.X64.Memory_Sems.same_mem_get_heap_val64",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j])) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val written_buffer_down64_aux2
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale8 (i + 1) <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale8 (i + 1) /\ j < base + scale8 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) | [
"recursion"
] | Vale.X64.Memory_Sems.written_buffer_down64_aux2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))} ->
base: Prims.nat{base == Vale.X64.Memory.buffer_addr b h} ->
n: Prims.nat{n == Vale.X64.Memory.buffer_length b} ->
k: Prims.nat{k > i} ->
h1: Vale.Arch.HeapImpl.vale_heap{h1 == Vale.X64.Memory.buffer_write b i v h} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h) mem1} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{ Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h1) mem2 /\
(forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base + Vale.X64.Memory.scale8 (i + 1) <= j /\ j < base + k * 8 ==>
mem1.[ j ] == mem2.[ j ]) }
-> FStar.Pervasives.Lemma
(ensures
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j >= base + Vale.X64.Memory.scale8 (i + 1) /\ j < base + Vale.X64.Memory.scale8 n ==>
mem1.[ j ] == mem2.[ j ]) (decreases n - k) | {
"end_col": 7,
"end_line": 316,
"start_col": 4,
"start_line": 310
} |
FStar.Pervasives.Lemma | val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8))) | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 = | false | null | true | let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down_p",
"LowStar.BufferView.Up.length_eq",
"Vale.Interop.Types.base_typ_as_type",
"Prims.unit",
"LowStar.BufferView.Up.put_sel",
"Vale.Interop.Heap_s.hs_of_mem",
"LowStar.BufferView.Up.as_seq_sel",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"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",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8))) | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8))) | [] | Vale.X64.Memory_Sems.same_mem_eq_slices64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
h1:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h1))} ->
h2: Vale.Arch.HeapImpl.vale_heap{h2 == Vale.X64.Memory.buffer_write b i v h1} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h1) mem1 b} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h2) mem2 b}
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h1 b) k ==
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h2 b) k)
(ensures
k * 8 + 8 <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) /\
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h1))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 8)
(k * 8 + 8) ==
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h2))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 8)
(k * 8 + 8)) | {
"end_col": 19,
"end_line": 226,
"start_col": 50,
"start_line": 218
} |
FStar.Pervasives.Lemma | val low_lemma_store_mem128_full (b:buffer128) (i:nat) (v:quad32) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr128 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v h) hid
(S.update_heap128 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 16 (heap_taint (coerce vfh)) t)
)) | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
() | val low_lemma_store_mem128_full (b:buffer128) (i:nat) (v:quad32) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr128 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v h) hid
(S.update_heap128 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 16 (heap_taint (coerce vfh)) t)
))
let low_lemma_store_mem128_full b i v vfh t hid = | false | null | true | let h, mt, hk = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.memtaint",
"Prims.unit",
"Vale.X64.Memory_Sems.lemma_is_full_update",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.Arch.MachineHeap.same_mem_get_heap_val128",
"Vale.X64.Memory_Sems.in_bounds128",
"Vale.Arch.MachineHeap.frame_update_heap128",
"Vale.X64.Memory_Sems.low_lemma_store_mem128",
"Vale.Lib.Map16.get",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap128",
"Vale.X64.Memory_Sems.get_heap",
"Vale.X64.Memory.buffer_write",
"Vale.X64.Memory.vuint128",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Prims.l_Forall",
"Prims.int",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.eq2",
"FStar.Map.sel",
"Prims.l_or",
"Vale.Arch.Heap.heap_taint",
"Vale.X64.Machine_Semantics_s.update_n",
"Vale.X64.Memory_Sems.coerce",
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale16",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap' | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val low_lemma_store_mem128_full (b:buffer128) (i:nat) (v:quad32) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b /\
valid_layout_buffer b vfh.vf_layout h true /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let h = Map16.get vfh.vf_heaplets hid in
let ptr = buffer_addr b h + scale16 i in
buffer_addr b vfh.vf_heap == buffer_addr b h /\
valid_addr128 ptr (heap_get (coerce vfh)) /\
is_full_update vfh (buffer_write b i v h) hid
(S.update_heap128 ptr v (heap_get (coerce vfh)))
(S.update_n ptr 16 (heap_taint (coerce vfh)) t)
)) | [] | Vale.X64.Memory_Sems.low_lemma_store_mem128_full | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
v: Vale.X64.Memory.quad32 ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
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 /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h true /\
Vale.X64.Memory.valid_taint_buf128 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let h = Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale16 i in
Vale.X64.Memory.buffer_addr b (Mkvale_full_heap?.vf_heap vfh) ==
Vale.X64.Memory.buffer_addr b h /\
Vale.Arch.MachineHeap_s.valid_addr128 ptr
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)) /\
Vale.X64.Memory_Sems.is_full_update vfh
(Vale.X64.Memory.buffer_write b i v h)
hid
(Vale.Arch.MachineHeap_s.update_heap128 ptr
v
(Vale.Arch.Heap.heap_get (Vale.X64.Memory_Sems.coerce vfh)))
(Vale.X64.Machine_Semantics_s.update_n ptr
16
(Vale.Arch.Heap.heap_taint (Vale.X64.Memory_Sems.coerce vfh))
t))) | {
"end_col": 4,
"end_line": 1007,
"start_col": 49,
"start_line": 992
} |
FStar.Pervasives.Lemma | val lemma_is_full_update
(vfh: vale_full_heap)
(h hk hk': vale_heap)
(k: heaplet_id)
(mh mh' mhk mhk': machine_heap)
(mt mt': memtaint)
(t: base_typ)
(b: buffer t)
(ptr: int)
(v_size index: nat)
(v: base_typ_as_vale_type t)
(tn: taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\ mem_inv vfh /\ buffer_readable hk b /\
buffer_writeable b /\ index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\ h == vfh.vf_heap /\ hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\ mhk == hk.mh /\ ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\ valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\ is_machine_heap_update mh mh' /\
upd_heap h mh' == buffer_write b index v h /\ is_machine_heap_update mhk mhk' /\
upd_heap hk mhk' == buffer_write b index v hk /\
(forall j. {:pattern mh.[ j ]\/mh'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mh.[ j ] == mh'.[ j ]) /\
(forall j. {:pattern mhk.[ j ]\/mhk'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mhk.[ j ] == mhk'.[ j ]) /\ 0 <= scale_by v_size index /\
scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i. {:pattern mh'.[ i ]\/mhk'.[ i ]}
i >= ptr /\ i < ptr + v_size ==> mh'.[ i ] == mhk'.[ i ]) /\ True)
(ensures is_full_update vfh hk' k mh' mt') | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"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.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": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"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.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_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.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
() | val lemma_is_full_update
(vfh: vale_full_heap)
(h hk hk': vale_heap)
(k: heaplet_id)
(mh mh' mhk mhk': machine_heap)
(mt mt': memtaint)
(t: base_typ)
(b: buffer t)
(ptr: int)
(v_size index: nat)
(v: base_typ_as_vale_type t)
(tn: taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\ mem_inv vfh /\ buffer_readable hk b /\
buffer_writeable b /\ index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\ h == vfh.vf_heap /\ hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\ mhk == hk.mh /\ ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\ valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\ is_machine_heap_update mh mh' /\
upd_heap h mh' == buffer_write b index v h /\ is_machine_heap_update mhk mhk' /\
upd_heap hk mhk' == buffer_write b index v hk /\
(forall j. {:pattern mh.[ j ]\/mh'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mh.[ j ] == mh'.[ j ]) /\
(forall j. {:pattern mhk.[ j ]\/mhk'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mhk.[ j ] == mhk'.[ j ]) /\ 0 <= scale_by v_size index /\
scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i. {:pattern mh'.[ i ]\/mhk'.[ i ]}
i >= ptr /\ i < ptr + v_size ==> mh'.[ i ] == mhk'.[ i ]) /\ True)
(ensures is_full_update vfh hk' k mh' mt')
let lemma_is_full_update
(vfh: vale_full_heap)
(h hk hk': vale_heap)
(k: heaplet_id)
(mh mh' mhk mhk': machine_heap)
(mt mt': memtaint)
(t: base_typ)
(b: buffer t)
(ptr: int)
(v_size index: nat)
(v: base_typ_as_vale_type t)
(tn: taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\ mem_inv vfh /\ buffer_readable hk b /\
buffer_writeable b /\ index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\ h == vfh.vf_heap /\ hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\ mhk == hk.mh /\ ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\ valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\ is_machine_heap_update mh mh' /\
upd_heap h mh' == buffer_write b index v h /\ is_machine_heap_update mhk mhk' /\
upd_heap hk mhk' == buffer_write b index v hk /\
(forall j. {:pattern mh.[ j ]\/mh'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mh.[ j ] == mh'.[ j ]) /\
(forall j. {:pattern mhk.[ j ]\/mhk'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mhk.[ j ] == mhk'.[ j ]) /\ 0 <= scale_by v_size index /\
scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i. {:pattern mh'.[ i ]\/mhk'.[ i ]}
i >= ptr /\ i < ptr + v_size ==> mh'.[ i ] == mhk'.[ i ]) /\ True)
(ensures is_full_update vfh hk' k mh' mt') = | false | null | true | reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j: heaplet_id)
: Lemma (requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)] =
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
() | {
"checked_file": "Vale.X64.Memory_Sems.fst.checked",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
"lemma"
] | [
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.X64.Memory.memtaint",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapImpl.buffer",
"Prims.int",
"Prims.nat",
"Vale.X64.Memory.base_typ_as_vale_type",
"Vale.Arch.HeapTypes_s.taint",
"Prims.unit",
"Vale.Interop.Heap_s.list_disjoint_or_eq_reveal",
"Prims._assert",
"FStar.Map.equal",
"Vale.Lib.Map16.equal",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets",
"Vale.Lib.Map16.upd",
"Prims.l_not",
"Prims.eq2",
"Prims.squash",
"Vale.Lib.Map16.sel",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"Vale.Interop.down_up_identity",
"FStar.Ghost.reveal",
"Vale.Interop.Heap_s.interop_heap",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__ih",
"Vale.Def.Types_s.nat8",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"FStar.Map.t",
"Vale.Def.Words_s.nat8",
"FStar.Map.concat",
"FStar.Map.restrict",
"FStar.Set.set",
"FStar.Set.intersect",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplet_sets",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"FStar.Map.domain",
"Vale.X64.Memory_Sems.coerce",
"Vale.Arch.Heap.heap_impl",
"Vale.Arch.Heap.heap_upd",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Prims.l_and",
"Prims.b2t",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_heaplets_initialized",
"Vale.X64.Memory.mem_inv",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.Memory.buffer_writeable",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.X64.Memory.buffer_as_seq",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale_by",
"Vale.X64.Machine_Semantics_s.update_n",
"Vale.Arch.Heap.heap_taint",
"Vale.X64.Memory.buffer_write",
"Vale.X64.Memory.valid_layout_buffer",
"Vale.X64.Memory.valid_taint_buf",
"Vale.Arch.MachineHeap_s.is_machine_heap_update",
"Vale.X64.Memory_Sems.upd_heap",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Vale.X64.Memory.op_String_Access",
"Prims.op_LessThanOrEqual",
"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.l_True",
"Vale.X64.Memory_Sems.is_full_update"
] | [] | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(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))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
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
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
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
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
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
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt') | false | false | Vale.X64.Memory_Sems.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_is_full_update
(vfh: vale_full_heap)
(h hk hk': vale_heap)
(k: heaplet_id)
(mh mh' mhk mhk': machine_heap)
(mt mt': memtaint)
(t: base_typ)
(b: buffer t)
(ptr: int)
(v_size index: nat)
(v: base_typ_as_vale_type t)
(tn: taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\ mem_inv vfh /\ buffer_readable hk b /\
buffer_writeable b /\ index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\ h == vfh.vf_heap /\ hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\ mhk == hk.mh /\ ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\ valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\ is_machine_heap_update mh mh' /\
upd_heap h mh' == buffer_write b index v h /\ is_machine_heap_update mhk mhk' /\
upd_heap hk mhk' == buffer_write b index v hk /\
(forall j. {:pattern mh.[ j ]\/mh'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mh.[ j ] == mh'.[ j ]) /\
(forall j. {:pattern mhk.[ j ]\/mhk'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mhk.[ j ] == mhk'.[ j ]) /\ 0 <= scale_by v_size index /\
scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i. {:pattern mh'.[ i ]\/mhk'.[ i ]}
i >= ptr /\ i < ptr + v_size ==> mh'.[ i ] == mhk'.[ i ]) /\ True)
(ensures is_full_update vfh hk' k mh' mt') | [] | Vale.X64.Memory_Sems.lemma_is_full_update | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
h: Vale.Arch.HeapImpl.vale_heap ->
hk: Vale.Arch.HeapImpl.vale_heap ->
hk': Vale.Arch.HeapImpl.vale_heap ->
k: Vale.Arch.HeapImpl.heaplet_id ->
mh: Vale.Arch.MachineHeap_s.machine_heap ->
mh': Vale.Arch.MachineHeap_s.machine_heap ->
mhk: Vale.Arch.MachineHeap_s.machine_heap ->
mhk': Vale.Arch.MachineHeap_s.machine_heap ->
mt: Vale.X64.Memory.memtaint ->
mt': Vale.X64.Memory.memtaint ->
t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.Arch.HeapImpl.buffer t ->
ptr: Prims.int ->
v_size: Prims.nat ->
index: Prims.nat ->
v: Vale.X64.Memory.base_typ_as_vale_type t ->
tn: Vale.Arch.HeapTypes_s.taint
-> FStar.Pervasives.Lemma
(requires
Mkvale_heap_layout_inner?.vl_heaplets_initialized (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout
vfh)) /\ Vale.X64.Memory.mem_inv vfh /\ Vale.X64.Memory.buffer_readable hk b /\
Vale.X64.Memory.buffer_writeable b /\
index < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq hk b) /\
mt == Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh) /\
h == Mkvale_full_heap?.vf_heap vfh /\
hk == Vale.Lib.Map16.sel (Mkvale_full_heap?.vf_heaplets vfh) k /\ mh == ValeHeap?.mh h /\
mhk == ValeHeap?.mh hk /\
ptr == Vale.X64.Memory.buffer_addr b hk + Vale.X64.Memory.scale_by v_size index /\
mt' ==
Vale.X64.Machine_Semantics_s.update_n ptr
v_size
(Vale.Arch.Heap.heap_taint (Vale.X64.Memory_Sems.coerce vfh))
tn /\ hk' == Vale.X64.Memory.buffer_write b index v hk /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) hk true /\
Vale.X64.Memory.valid_taint_buf b hk mt tn /\
Vale.Arch.MachineHeap_s.is_machine_heap_update mh mh' /\
Vale.X64.Memory_Sems.upd_heap h mh' == Vale.X64.Memory.buffer_write b index v h /\
Vale.Arch.MachineHeap_s.is_machine_heap_update mhk mhk' /\
Vale.X64.Memory_Sems.upd_heap hk mhk' == Vale.X64.Memory.buffer_write b index v hk /\
(forall (j: Prims.int). {:pattern mh.[ j ]\/mh'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mh.[ j ] == mh'.[ j ]) /\
(forall (j: Prims.int). {:pattern mhk.[ j ]\/mhk'.[ j ]}
j < ptr \/ j >= ptr + v_size ==> mhk.[ j ] == mhk'.[ j ]) /\
0 <= Vale.X64.Memory.scale_by v_size index /\
Vale.X64.Memory.scale_by v_size index + v_size <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) /\
(forall (i: Prims.int). {:pattern mh'.[ i ]\/mhk'.[ i ]}
i >= ptr /\ i < ptr + v_size ==> mh'.[ i ] == mhk'.[ i ]) /\ Prims.l_True)
(ensures Vale.X64.Memory_Sems.is_full_update vfh hk' k mh' mt') | {
"end_col": 4,
"end_line": 705,
"start_col": 2,
"start_line": 688
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul | let is_ascii_char (c: Char.char) = | false | null | false | UInt32.lt (Char.u32_of_char c) 0x80ul | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"FStar.Char.char",
"FStar.UInt32.lt",
"FStar.Char.u32_of_char",
"FStar.UInt32.__uint_to_t",
"Prims.bool"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of | false | true | LowStar.Literal.fsti | {
"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"
} | null | val is_ascii_char : c: FStar.Char.char -> Prims.bool | [] | LowStar.Literal.is_ascii_char | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | c: FStar.Char.char -> Prims.bool | {
"end_col": 72,
"end_line": 36,
"start_col": 35,
"start_line": 36
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ascii_char = c:Char.char{is_ascii_char c} | let ascii_char = | false | null | false | c: Char.char{is_ascii_char c} | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"FStar.Char.char",
"Prims.b2t",
"LowStar.Literal.is_ascii_char"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul | false | true | LowStar.Literal.fsti | {
"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"
} | null | val ascii_char : Type0 | [] | LowStar.Literal.ascii_char | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Type0 | {
"end_col": 45,
"end_line": 38,
"start_col": 17,
"start_line": 38
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s) | let is_ascii_string (s: string) = | false | null | false | List.Tot.for_all is_ascii_char (String.list_of_string s) | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"Prims.string",
"FStar.List.Tot.Base.for_all",
"FStar.String.char",
"LowStar.Literal.is_ascii_char",
"FStar.String.list_of_string",
"Prims.bool"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c} | false | true | LowStar.Literal.fsti | {
"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"
} | null | val is_ascii_string : s: Prims.string -> Prims.bool | [] | LowStar.Literal.is_ascii_string | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string -> Prims.bool | {
"end_col": 58,
"end_line": 41,
"start_col": 2,
"start_line": 41
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ascii_string = s:string{is_ascii_string s} | let ascii_string = | false | null | false | s: string{is_ascii_string s} | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"Prims.string",
"Prims.b2t",
"LowStar.Literal.is_ascii_string"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c}
let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s) | false | true | LowStar.Literal.fsti | {
"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"
} | null | val ascii_string : Type0 | [] | LowStar.Literal.ascii_string | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Type0 | {
"end_col": 46,
"end_line": 43,
"start_col": 19,
"start_line": 43
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buffer_of_literal_post (s: ascii_string) (h0: HS.mem) (b: IB.ibuffer UInt8.t) (h1: HS.mem) =
IB.frameOf b == HS.root /\ // is this really useful?
IB.recallable b /\ (
// An inlined version of alloc_post_mem_common, without the unused_in
// condition, which would contradict the Stack annotation
let s = u8s_of_ascii_string s in
IB.live h1 b /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
HS.get_tip h1 == HS.get_tip h0 /\
B.(modifies loc_none h0 h1) /\
B.as_seq h1 b == s) | let buffer_of_literal_post (s: ascii_string) (h0: HS.mem) (b: IB.ibuffer UInt8.t) (h1: HS.mem) = | false | null | false | IB.frameOf b == HS.root /\ IB.recallable b /\
(let s = u8s_of_ascii_string s in
IB.live h1 b /\ (Map.domain (HS.get_hmap h1)) `Set.equal` (Map.domain (HS.get_hmap h0)) /\
HS.get_tip h1 == HS.get_tip h0 /\ B.(modifies loc_none h0 h1) /\ B.as_seq h1 b == s) | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"LowStar.Literal.ascii_string",
"FStar.Monotonic.HyperStack.mem",
"LowStar.ImmutableBuffer.ibuffer",
"FStar.UInt8.t",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.ImmutableBuffer.immutable_preorder",
"FStar.Monotonic.HyperHeap.root",
"LowStar.Monotonic.Buffer.recallable",
"LowStar.Monotonic.Buffer.live",
"FStar.Set.equal",
"FStar.Map.domain",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.HyperStack.get_hmap",
"FStar.Monotonic.HyperStack.get_tip",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.List.Tot.Base.length",
"FStar.String.char",
"FStar.String.list_of_string",
"LowStar.Literal.u8s_of_ascii_string",
"Prims.logical"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c}
let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s)
let ascii_string = s:string{is_ascii_string s}
let for_all_tail #a p (l: list a { Cons? l }): Lemma
(requires (List.Tot.for_all p l))
(ensures (List.Tot.for_all p (List.Tot.tl l)))
=
()
let ascii_chars_of_ascii_string (s: ascii_string):
l:list ascii_char { List.Tot.length l = String.length s }
= List.Tot.list_refb #(Char.char) #_ (String.list_of_string s)
let u8_of_ascii_char (c: ascii_char): x:UInt8.t{ UInt8.v x = Char.int_of_char c } =
let x32 = Char.u32_of_char c in
assert_norm (pow2 24 * pow2 8 = pow2 32);
Math.Lemmas.modulo_modulo_lemma (UInt32.v x32) (pow2 24) (pow2 8);
Int.Cast.Full.uint32_to_uint8 x32
/// This means that if a string literal only contains ASCII, then we can easily
/// reflect its contents in terms of uint8's, without having to talk about the utf8
/// encoding.
/// TODO: lemma: S.index (u8s_of_string s) i = String.index s i
/// (cannot be proven right now because we don't know much about String.index)
/// (is this even what we want? should we do everything in terms of list_of_string?)
let u8s_of_ascii_string (s: ascii_string):
ss:Seq.seq UInt8.t { Seq.length ss = List.Tot.length (String.list_of_string s) }
=
let cs = List.Tot.map u8_of_ascii_char (ascii_chars_of_ascii_string s) in
Seq.seq_of_list cs | false | true | LowStar.Literal.fsti | {
"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"
} | null | val buffer_of_literal_post : s: LowStar.Literal.ascii_string ->
h0: FStar.Monotonic.HyperStack.mem ->
b: LowStar.ImmutableBuffer.ibuffer FStar.UInt8.t ->
h1: FStar.Monotonic.HyperStack.mem
-> Prims.logical | [] | LowStar.Literal.buffer_of_literal_post | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: LowStar.Literal.ascii_string ->
h0: FStar.Monotonic.HyperStack.mem ->
b: LowStar.ImmutableBuffer.ibuffer FStar.UInt8.t ->
h1: FStar.Monotonic.HyperStack.mem
-> Prims.logical | {
"end_col": 21,
"end_line": 83,
"start_col": 2,
"start_line": 74
} |
|
Prims.Tot | val u8_of_ascii_char (c: ascii_char) : x: UInt8.t{UInt8.v x = Char.int_of_char c} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let u8_of_ascii_char (c: ascii_char): x:UInt8.t{ UInt8.v x = Char.int_of_char c } =
let x32 = Char.u32_of_char c in
assert_norm (pow2 24 * pow2 8 = pow2 32);
Math.Lemmas.modulo_modulo_lemma (UInt32.v x32) (pow2 24) (pow2 8);
Int.Cast.Full.uint32_to_uint8 x32 | val u8_of_ascii_char (c: ascii_char) : x: UInt8.t{UInt8.v x = Char.int_of_char c}
let u8_of_ascii_char (c: ascii_char) : x: UInt8.t{UInt8.v x = Char.int_of_char c} = | false | null | false | let x32 = Char.u32_of_char c in
assert_norm (pow2 24 * pow2 8 = pow2 32);
Math.Lemmas.modulo_modulo_lemma (UInt32.v x32) (pow2 24) (pow2 8);
Int.Cast.Full.uint32_to_uint8 x32 | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"LowStar.Literal.ascii_char",
"FStar.Int.Cast.uint32_to_uint8",
"Prims.unit",
"FStar.Math.Lemmas.modulo_modulo_lemma",
"FStar.UInt32.v",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"FStar.Char.char_code",
"FStar.Char.u32_of_char",
"FStar.UInt8.t",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt8.n",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt8.v",
"FStar.Char.int_of_char"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c}
let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s)
let ascii_string = s:string{is_ascii_string s}
let for_all_tail #a p (l: list a { Cons? l }): Lemma
(requires (List.Tot.for_all p l))
(ensures (List.Tot.for_all p (List.Tot.tl l)))
=
()
let ascii_chars_of_ascii_string (s: ascii_string):
l:list ascii_char { List.Tot.length l = String.length s }
= List.Tot.list_refb #(Char.char) #_ (String.list_of_string s) | false | false | LowStar.Literal.fsti | {
"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"
} | null | val u8_of_ascii_char (c: ascii_char) : x: UInt8.t{UInt8.v x = Char.int_of_char c} | [] | LowStar.Literal.u8_of_ascii_char | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | c: LowStar.Literal.ascii_char -> x: FStar.UInt8.t{FStar.UInt8.v x = FStar.Char.int_of_char c} | {
"end_col": 35,
"end_line": 59,
"start_col": 83,
"start_line": 55
} |
Prims.Tot | val ascii_chars_of_ascii_string (s: ascii_string)
: l: list ascii_char {List.Tot.length l = String.length s} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ascii_chars_of_ascii_string (s: ascii_string):
l:list ascii_char { List.Tot.length l = String.length s }
= List.Tot.list_refb #(Char.char) #_ (String.list_of_string s) | val ascii_chars_of_ascii_string (s: ascii_string)
: l: list ascii_char {List.Tot.length l = String.length s}
let ascii_chars_of_ascii_string (s: ascii_string)
: l: list ascii_char {List.Tot.length l = String.length s} = | false | null | false | List.Tot.list_refb #(Char.char) #_ (String.list_of_string s) | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"LowStar.Literal.ascii_string",
"FStar.List.Tot.Base.list_refb",
"FStar.Char.char",
"LowStar.Literal.is_ascii_char",
"FStar.String.list_of_string",
"Prims.list",
"LowStar.Literal.ascii_char",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.String.length"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c}
let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s)
let ascii_string = s:string{is_ascii_string s}
let for_all_tail #a p (l: list a { Cons? l }): Lemma
(requires (List.Tot.for_all p l))
(ensures (List.Tot.for_all p (List.Tot.tl l)))
=
()
let ascii_chars_of_ascii_string (s: ascii_string): | false | false | LowStar.Literal.fsti | {
"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"
} | null | val ascii_chars_of_ascii_string (s: ascii_string)
: l: list ascii_char {List.Tot.length l = String.length s} | [] | LowStar.Literal.ascii_chars_of_ascii_string | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: LowStar.Literal.ascii_string
-> l: Prims.list LowStar.Literal.ascii_char {FStar.List.Tot.Base.length l = FStar.String.length s} | {
"end_col": 62,
"end_line": 53,
"start_col": 2,
"start_line": 53
} |
Prims.Tot | val u8s_of_ascii_string (s: ascii_string)
: ss: Seq.seq UInt8.t {Seq.length ss = List.Tot.length (String.list_of_string s)} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let u8s_of_ascii_string (s: ascii_string):
ss:Seq.seq UInt8.t { Seq.length ss = List.Tot.length (String.list_of_string s) }
=
let cs = List.Tot.map u8_of_ascii_char (ascii_chars_of_ascii_string s) in
Seq.seq_of_list cs | val u8s_of_ascii_string (s: ascii_string)
: ss: Seq.seq UInt8.t {Seq.length ss = List.Tot.length (String.list_of_string s)}
let u8s_of_ascii_string (s: ascii_string)
: ss: Seq.seq UInt8.t {Seq.length ss = List.Tot.length (String.list_of_string s)} = | false | null | false | let cs = List.Tot.map u8_of_ascii_char (ascii_chars_of_ascii_string s) in
Seq.seq_of_list cs | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
"total"
] | [
"LowStar.Literal.ascii_string",
"FStar.Seq.Properties.seq_of_list",
"FStar.UInt8.t",
"Prims.list",
"FStar.List.Tot.Base.map",
"LowStar.Literal.ascii_char",
"LowStar.Literal.u8_of_ascii_char",
"LowStar.Literal.ascii_chars_of_ascii_string",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.List.Tot.Base.length",
"FStar.String.char",
"FStar.String.list_of_string"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c}
let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s)
let ascii_string = s:string{is_ascii_string s}
let for_all_tail #a p (l: list a { Cons? l }): Lemma
(requires (List.Tot.for_all p l))
(ensures (List.Tot.for_all p (List.Tot.tl l)))
=
()
let ascii_chars_of_ascii_string (s: ascii_string):
l:list ascii_char { List.Tot.length l = String.length s }
= List.Tot.list_refb #(Char.char) #_ (String.list_of_string s)
let u8_of_ascii_char (c: ascii_char): x:UInt8.t{ UInt8.v x = Char.int_of_char c } =
let x32 = Char.u32_of_char c in
assert_norm (pow2 24 * pow2 8 = pow2 32);
Math.Lemmas.modulo_modulo_lemma (UInt32.v x32) (pow2 24) (pow2 8);
Int.Cast.Full.uint32_to_uint8 x32
/// This means that if a string literal only contains ASCII, then we can easily
/// reflect its contents in terms of uint8's, without having to talk about the utf8
/// encoding.
/// TODO: lemma: S.index (u8s_of_string s) i = String.index s i
/// (cannot be proven right now because we don't know much about String.index)
/// (is this even what we want? should we do everything in terms of list_of_string?)
let u8s_of_ascii_string (s: ascii_string): | false | false | LowStar.Literal.fsti | {
"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"
} | null | val u8s_of_ascii_string (s: ascii_string)
: ss: Seq.seq UInt8.t {Seq.length ss = List.Tot.length (String.list_of_string s)} | [] | LowStar.Literal.u8s_of_ascii_string | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: LowStar.Literal.ascii_string
-> ss:
FStar.Seq.Base.seq FStar.UInt8.t
{FStar.Seq.Base.length ss = FStar.List.Tot.Base.length (FStar.String.list_of_string s)} | {
"end_col": 20,
"end_line": 71,
"start_col": 1,
"start_line": 69
} |
FStar.HyperStack.ST.Stack | val buf_len_of_literal (s: string)
: ST.Stack (IB.ibuffer UInt8.t & UInt32.t)
(requires
(fun _ ->
normalize (is_ascii_string s) /\
normalize (List.Tot.length (String.list_of_string s) < pow2 32)))
(ensures
(fun h0 r h1 ->
let b, l = r in
buffer_of_literal_post s h0 b h1 /\
UInt32.v l = normalize_term (List.Tot.length (String.list_of_string s)) /\
UInt32.v l = IB.length b)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let buf_len_of_literal (s: string):
ST.Stack (IB.ibuffer UInt8.t & UInt32.t)
(requires (fun _ ->
normalize (is_ascii_string s) /\
normalize (List.Tot.length (String.list_of_string s) < pow2 32)))
(ensures (fun h0 r h1 ->
let b, l = r in
buffer_of_literal_post s h0 b h1 /\
UInt32.v l = normalize_term (List.Tot.length (String.list_of_string s)) /\
UInt32.v l = IB.length b))
=
[@@inline_let]
let l = normalize_term (UInt32.uint_to_t (List.Tot.length (String.list_of_string s))) in
buffer_of_literal s, l | val buf_len_of_literal (s: string)
: ST.Stack (IB.ibuffer UInt8.t & UInt32.t)
(requires
(fun _ ->
normalize (is_ascii_string s) /\
normalize (List.Tot.length (String.list_of_string s) < pow2 32)))
(ensures
(fun h0 r h1 ->
let b, l = r in
buffer_of_literal_post s h0 b h1 /\
UInt32.v l = normalize_term (List.Tot.length (String.list_of_string s)) /\
UInt32.v l = IB.length b))
let buf_len_of_literal (s: string)
: ST.Stack (IB.ibuffer UInt8.t & UInt32.t)
(requires
(fun _ ->
normalize (is_ascii_string s) /\
normalize (List.Tot.length (String.list_of_string s) < pow2 32)))
(ensures
(fun h0 r h1 ->
let b, l = r in
buffer_of_literal_post s h0 b h1 /\
UInt32.v l = normalize_term (List.Tot.length (String.list_of_string s)) /\
UInt32.v l = IB.length b)) = | true | null | false | [@@ inline_let ]let l =
normalize_term (UInt32.uint_to_t (List.Tot.length (String.list_of_string s)))
in
buffer_of_literal s, l | {
"checked_file": "LowStar.Literal.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.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.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [] | [
"Prims.string",
"FStar.Pervasives.Native.Mktuple2",
"LowStar.ImmutableBuffer.ibuffer",
"FStar.UInt8.t",
"FStar.UInt32.t",
"FStar.Pervasives.Native.tuple2",
"LowStar.Literal.buffer_of_literal",
"FStar.Pervasives.normalize_term",
"FStar.UInt32.uint_to_t",
"FStar.List.Tot.Base.length",
"FStar.String.char",
"FStar.String.list_of_string",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"FStar.Pervasives.normalize",
"Prims.b2t",
"LowStar.Literal.is_ascii_string",
"Prims.op_LessThan",
"Prims.pow2",
"LowStar.Literal.buffer_of_literal_post",
"Prims.op_Equality",
"FStar.UInt.uint_t",
"FStar.UInt32.n",
"FStar.UInt32.v",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"LowStar.Monotonic.Buffer.length",
"LowStar.ImmutableBuffer.immutable_preorder"
] | [] | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c}
let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s)
let ascii_string = s:string{is_ascii_string s}
let for_all_tail #a p (l: list a { Cons? l }): Lemma
(requires (List.Tot.for_all p l))
(ensures (List.Tot.for_all p (List.Tot.tl l)))
=
()
let ascii_chars_of_ascii_string (s: ascii_string):
l:list ascii_char { List.Tot.length l = String.length s }
= List.Tot.list_refb #(Char.char) #_ (String.list_of_string s)
let u8_of_ascii_char (c: ascii_char): x:UInt8.t{ UInt8.v x = Char.int_of_char c } =
let x32 = Char.u32_of_char c in
assert_norm (pow2 24 * pow2 8 = pow2 32);
Math.Lemmas.modulo_modulo_lemma (UInt32.v x32) (pow2 24) (pow2 8);
Int.Cast.Full.uint32_to_uint8 x32
/// This means that if a string literal only contains ASCII, then we can easily
/// reflect its contents in terms of uint8's, without having to talk about the utf8
/// encoding.
/// TODO: lemma: S.index (u8s_of_string s) i = String.index s i
/// (cannot be proven right now because we don't know much about String.index)
/// (is this even what we want? should we do everything in terms of list_of_string?)
let u8s_of_ascii_string (s: ascii_string):
ss:Seq.seq UInt8.t { Seq.length ss = List.Tot.length (String.list_of_string s) }
=
let cs = List.Tot.map u8_of_ascii_char (ascii_chars_of_ascii_string s) in
Seq.seq_of_list cs
unfold let buffer_of_literal_post (s: ascii_string) (h0: HS.mem) (b: IB.ibuffer UInt8.t) (h1: HS.mem) =
IB.frameOf b == HS.root /\ // is this really useful?
IB.recallable b /\ (
// An inlined version of alloc_post_mem_common, without the unused_in
// condition, which would contradict the Stack annotation
let s = u8s_of_ascii_string s in
IB.live h1 b /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
HS.get_tip h1 == HS.get_tip h0 /\
B.(modifies loc_none h0 h1) /\
B.as_seq h1 b == s)
/// Consequently, this function becomes in C a simple cast from ``const char *`` to
/// ``char *``, since immutable buffers don't (yet) have the ``const`` attribute in
/// KaRaMeL. (This is unsavory, and should be fixed later.) This way, a string
/// literal can be seen as an immutable buffer and passed around as such.
/// This function checks at extraction-time that its argument is a literal.
val buffer_of_literal: (s: ascii_string) ->
ST.Stack (IB.ibuffer UInt8.t)
(requires (fun _ -> String.length s < pow2 32))
(ensures buffer_of_literal_post s)
/// .. note::
///
/// This literal will be zero-terminated, but since we do not require that the
/// string literal be zero-free, the trailing zero will be ignored and unused. This
/// means that we won't be able to use the C standard library functions for string
/// manipulation and will instead have to pass lengths at run-time.
/// Rather than having to write ``assert_norm`` by hand, this convenient wrapper
/// relies on the normalizer to discharge all the relevant proof obligations, and
/// synthesizes the length of the resulting buffer. The pair has no cost: KaRaMeL
/// guarantees that it will be eliminated.
unfold
let buf_len_of_literal (s: string):
ST.Stack (IB.ibuffer UInt8.t & UInt32.t)
(requires (fun _ ->
normalize (is_ascii_string s) /\
normalize (List.Tot.length (String.list_of_string s) < pow2 32)))
(ensures (fun h0 r h1 ->
let b, l = r in
buffer_of_literal_post s h0 b h1 /\
UInt32.v l = normalize_term (List.Tot.length (String.list_of_string s)) /\
UInt32.v l = IB.length b)) | false | false | LowStar.Literal.fsti | {
"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"
} | null | val buf_len_of_literal (s: string)
: ST.Stack (IB.ibuffer UInt8.t & UInt32.t)
(requires
(fun _ ->
normalize (is_ascii_string s) /\
normalize (List.Tot.length (String.list_of_string s) < pow2 32)))
(ensures
(fun h0 r h1 ->
let b, l = r in
buffer_of_literal_post s h0 b h1 /\
UInt32.v l = normalize_term (List.Tot.length (String.list_of_string s)) /\
UInt32.v l = IB.length b)) | [] | LowStar.Literal.buf_len_of_literal | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string
-> FStar.HyperStack.ST.Stack (LowStar.ImmutableBuffer.ibuffer FStar.UInt8.t * FStar.UInt32.t) | {
"end_col": 24,
"end_line": 120,
"start_col": 2,
"start_line": 118
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let (@|) #a #l1 #l2 = append #a #l1 #l2 | let op_At_Bar #a #l1 #l2 = | false | null | false | append #a #l1 #l2 | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.len_t",
"FStar.Vector.Base.append",
"FStar.Vector.Base.raw",
"FStar.UInt.size",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.UInt32.add"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a
/// `v.[i]` is shorthand for `index v i`
unfold let op_String_Access #a #l = index #a #l
/// `update v i x`:
/// - a new vector that differs from `v` only at index `i`, where it contains `x`.
/// - Incurs a full copy in KaRaMeL
/// - In OCaml, the new vector shares as much as possible with `v`
val update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Tot (raw a l)
/// `v.[i] <- x` is shorthand for `update v i x`
unfold let op_String_Assignment #a #l = update #a #l
/// `append v1 v2`:
/// - requires proving that the sum of the lengths of v1 and v2 still fit in a u32
/// - Incurs a full copy in KaRaMeL
/// - Amortized constant time in OCaml
val append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Tot (raw a U32.(l1 +^ l2)) | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val op_At_Bar : v1: FStar.Vector.Base.raw a l1 ->
v2: FStar.Vector.Base.raw a l2 {FStar.UInt.size (FStar.UInt32.v l1 + FStar.UInt32.v l2) 32}
-> FStar.Vector.Base.raw a (FStar.UInt32.add l1 l2) | [] | FStar.Vector.Base.op_At_Bar | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
v1: FStar.Vector.Base.raw a l1 ->
v2: FStar.Vector.Base.raw a l2 {FStar.UInt.size (FStar.UInt32.v l1 + FStar.UInt32.v l2) 32}
-> FStar.Vector.Base.raw a (FStar.UInt32.add l1 l2) | {
"end_col": 46,
"end_line": 188,
"start_col": 29,
"start_line": 188
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l} | let index_t (#a: Type) (#l: len_t) (v: raw a l) = | false | null | false | m: len_t{U32.v m < U32.v l} | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.len_t",
"FStar.Vector.Base.raw",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v` | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val index_t : v: FStar.Vector.Base.raw a l -> Type0 | [] | FStar.Vector.Base.index_t | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: FStar.Vector.Base.raw a l -> Type0 | {
"end_col": 30,
"end_line": 139,
"start_col": 4,
"start_line": 139
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2) | let equal (#a: Type) (#l: len_t) (v1 v2: raw a l) = | false | null | false | Seq.equal (reveal v1) (reveal v2) | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.len_t",
"FStar.Vector.Base.raw",
"FStar.Seq.Base.equal",
"FStar.Vector.Base.reveal",
"Prims.prop"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val equal : v1: FStar.Vector.Base.raw a l -> v2: FStar.Vector.Base.raw a l -> Prims.prop | [] | FStar.Vector.Base.equal | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v1: FStar.Vector.Base.raw a l -> v2: FStar.Vector.Base.raw a l -> Prims.prop | {
"end_col": 37,
"end_line": 115,
"start_col": 4,
"start_line": 115
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let len_t = U32.t | let len_t = | false | null | false | U32.t | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.UInt32.t"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
//////////////////////////////////////////////////////////////////////////////// | false | true | FStar.Vector.Base.fsti | {
"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"
} | null | val len_t : Prims.eqtype | [] | FStar.Vector.Base.len_t | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Prims.eqtype | {
"end_col": 17,
"end_line": 72,
"start_col": 12,
"start_line": 72
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_String_Access #a #l = index #a #l | let op_String_Access #a #l = | false | null | false | index #a #l | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.len_t",
"FStar.Vector.Base.index",
"FStar.Vector.Base.raw",
"FStar.Vector.Base.index_t"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val op_String_Access : v: FStar.Vector.Base.raw a l -> i: FStar.Vector.Base.index_t v -> a | [] | FStar.Vector.Base.op_String_Access | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: FStar.Vector.Base.raw a l -> i: FStar.Vector.Base.index_t v -> a | {
"end_col": 47,
"end_line": 158,
"start_col": 36,
"start_line": 158
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_String_Assignment #a #l = update #a #l | let op_String_Assignment #a #l = | false | null | false | update #a #l | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.len_t",
"FStar.Vector.Base.update",
"FStar.Vector.Base.raw",
"FStar.Vector.Base.index_t"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a
/// `v.[i]` is shorthand for `index v i`
unfold let op_String_Access #a #l = index #a #l
/// `update v i x`:
/// - a new vector that differs from `v` only at index `i`, where it contains `x`.
/// - Incurs a full copy in KaRaMeL
/// - In OCaml, the new vector shares as much as possible with `v`
val update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Tot (raw a l) | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val op_String_Assignment : v: FStar.Vector.Base.raw a l -> i: FStar.Vector.Base.index_t v -> x: a -> FStar.Vector.Base.raw a l | [] | FStar.Vector.Base.op_String_Assignment | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: FStar.Vector.Base.raw a l -> i: FStar.Vector.Base.index_t v -> x: a -> FStar.Vector.Base.raw a l | {
"end_col": 52,
"end_line": 173,
"start_col": 40,
"start_line": 173
} |
|
Prims.Tot | val op_Array_Access (#a: Type) (x: t a) (i: index_t (as_raw x)) : Tot a | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Array_Access
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
: Tot a
= (as_raw x).[i] | val op_Array_Access (#a: Type) (x: t a) (i: index_t (as_raw x)) : Tot a
let op_Array_Access (#a: Type) (x: t a) (i: index_t (as_raw x)) : Tot a = | false | null | false | (as_raw x).[ i ] | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.t",
"FStar.Vector.Base.index_t",
"FStar.Vector.Base.len",
"FStar.Vector.Base.as_raw",
"FStar.Vector.Base.op_String_Access"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a
/// `v.[i]` is shorthand for `index v i`
unfold let op_String_Access #a #l = index #a #l
/// `update v i x`:
/// - a new vector that differs from `v` only at index `i`, where it contains `x`.
/// - Incurs a full copy in KaRaMeL
/// - In OCaml, the new vector shares as much as possible with `v`
val update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Tot (raw a l)
/// `v.[i] <- x` is shorthand for `update v i x`
unfold let op_String_Assignment #a #l = update #a #l
/// `append v1 v2`:
/// - requires proving that the sum of the lengths of v1 and v2 still fit in a u32
/// - Incurs a full copy in KaRaMeL
/// - Amortized constant time in OCaml
val append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Tot (raw a U32.(l1 +^ l2))
/// `v1 @| v2`: shorthand for `append v1 v2`
unfold let (@|) #a #l1 #l2 = append #a #l1 #l2
/// `sub v i j`:
/// - the sub-vector of `v` starting from index `i` up to, but not including, `j`
/// - Constant time in KaRaMeL (just an addition on a pointer)
/// - Worst-case (log l) time in OCaml
val sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Tot (raw a U32.(j -^ i))
////////////////////////////////////////////////////////////////////////////////
/// Lemmas about the basic operations, all rather boring
/// -- Each is just a lifting specifying the corresponding operation on seq
////////////////////////////////////////////////////////////////////////////////
val reveal_init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Lemma
(ensures (reveal (init l contents) == Seq.init (U32.v l) contents))
[SMTPat (init l contents)]
val reveal_index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Lemma
(ensures (v.[i] == Seq.index (reveal v) (U32.v i)))
[SMTPat (v.[i])]
val reveal_update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Lemma
(ensures (reveal (v.[i] <- x) == Seq.upd (reveal v) (U32.v i) x))
[SMTPat (v.[i] <- x)]
val reveal_append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Lemma
(ensures (reveal (v1 @| v2) == Seq.append (reveal v1) (reveal v2)))
[SMTPat (v1 @| v2)]
val reveal_sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Lemma
(ensures (reveal (sub v i j) == S.slice (reveal v) (U32.v i) (U32.v j)))
[SMTPat (sub v i j)]
////////////////////////////////////////////////////////////////////////////////
/// Now, we have `Vector.Base.t`, abstractly, a raw vector paired with its u32 length
////////////////////////////////////////////////////////////////////////////////
val t:
a:Type u#a
-> Type u#a
/// Unlike raw vectors, t-vectors support decidable equality
val t_has_eq:
a:Type u#a
-> Lemma
(requires (hasEq a))
(ensures (hasEq (t a)))
[SMTPat (hasEq (t a))]
/// The length of a t-vector is a dynamically computable u32
val len:
#a:Type
-> t a
-> len_t
/// A convenience to access the length of a t-vector as a nat
[@@"deprecated: this will be moved to the ghost effect"]
let length (#a:Type) (x:t a) : nat = U32.v (len x)
/// Access the underlying raw vector
val as_raw:
#a:Type
-> x:t a
-> raw a (len x)
/// Promote a raw vector
val from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> x:t a{len x = l}
/// as_raw and from_raw are mutual inverses
val as_raw_from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (as_raw (from_raw v) == v))
[SMTPat (from_raw v)]
val from_raw_as_raw:
#a:Type
-> x:t a
-> Lemma (ensures (from_raw (as_raw x) == x))
[SMTPat (as_raw x)]
/// `v.(i)` accesses the ith element of v
unfold
let op_Array_Access
(#a:Type)
(x:t a)
(i:index_t (as_raw x)) | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val op_Array_Access (#a: Type) (x: t a) (i: index_t (as_raw x)) : Tot a | [] | FStar.Vector.Base.op_Array_Access | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Vector.Base.t a -> i: FStar.Vector.Base.index_t (FStar.Vector.Base.as_raw x) -> a | {
"end_col": 18,
"end_line": 313,
"start_col": 4,
"start_line": 313
} |
Prims.Tot | val op_Array_Assignment (#a: Type) (x: t a) (i: index_t (as_raw x)) (v: a) : Tot (t a) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Array_Assignment
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
(v:a)
: Tot (t a)
= from_raw ((as_raw x).[i] <- v) | val op_Array_Assignment (#a: Type) (x: t a) (i: index_t (as_raw x)) (v: a) : Tot (t a)
let op_Array_Assignment (#a: Type) (x: t a) (i: index_t (as_raw x)) (v: a) : Tot (t a) = | false | null | false | from_raw ((as_raw x).[ i ] <- v) | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.t",
"FStar.Vector.Base.index_t",
"FStar.Vector.Base.len",
"FStar.Vector.Base.as_raw",
"FStar.Vector.Base.from_raw",
"FStar.Vector.Base.op_String_Assignment"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a
/// `v.[i]` is shorthand for `index v i`
unfold let op_String_Access #a #l = index #a #l
/// `update v i x`:
/// - a new vector that differs from `v` only at index `i`, where it contains `x`.
/// - Incurs a full copy in KaRaMeL
/// - In OCaml, the new vector shares as much as possible with `v`
val update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Tot (raw a l)
/// `v.[i] <- x` is shorthand for `update v i x`
unfold let op_String_Assignment #a #l = update #a #l
/// `append v1 v2`:
/// - requires proving that the sum of the lengths of v1 and v2 still fit in a u32
/// - Incurs a full copy in KaRaMeL
/// - Amortized constant time in OCaml
val append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Tot (raw a U32.(l1 +^ l2))
/// `v1 @| v2`: shorthand for `append v1 v2`
unfold let (@|) #a #l1 #l2 = append #a #l1 #l2
/// `sub v i j`:
/// - the sub-vector of `v` starting from index `i` up to, but not including, `j`
/// - Constant time in KaRaMeL (just an addition on a pointer)
/// - Worst-case (log l) time in OCaml
val sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Tot (raw a U32.(j -^ i))
////////////////////////////////////////////////////////////////////////////////
/// Lemmas about the basic operations, all rather boring
/// -- Each is just a lifting specifying the corresponding operation on seq
////////////////////////////////////////////////////////////////////////////////
val reveal_init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Lemma
(ensures (reveal (init l contents) == Seq.init (U32.v l) contents))
[SMTPat (init l contents)]
val reveal_index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Lemma
(ensures (v.[i] == Seq.index (reveal v) (U32.v i)))
[SMTPat (v.[i])]
val reveal_update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Lemma
(ensures (reveal (v.[i] <- x) == Seq.upd (reveal v) (U32.v i) x))
[SMTPat (v.[i] <- x)]
val reveal_append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Lemma
(ensures (reveal (v1 @| v2) == Seq.append (reveal v1) (reveal v2)))
[SMTPat (v1 @| v2)]
val reveal_sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Lemma
(ensures (reveal (sub v i j) == S.slice (reveal v) (U32.v i) (U32.v j)))
[SMTPat (sub v i j)]
////////////////////////////////////////////////////////////////////////////////
/// Now, we have `Vector.Base.t`, abstractly, a raw vector paired with its u32 length
////////////////////////////////////////////////////////////////////////////////
val t:
a:Type u#a
-> Type u#a
/// Unlike raw vectors, t-vectors support decidable equality
val t_has_eq:
a:Type u#a
-> Lemma
(requires (hasEq a))
(ensures (hasEq (t a)))
[SMTPat (hasEq (t a))]
/// The length of a t-vector is a dynamically computable u32
val len:
#a:Type
-> t a
-> len_t
/// A convenience to access the length of a t-vector as a nat
[@@"deprecated: this will be moved to the ghost effect"]
let length (#a:Type) (x:t a) : nat = U32.v (len x)
/// Access the underlying raw vector
val as_raw:
#a:Type
-> x:t a
-> raw a (len x)
/// Promote a raw vector
val from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> x:t a{len x = l}
/// as_raw and from_raw are mutual inverses
val as_raw_from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (as_raw (from_raw v) == v))
[SMTPat (from_raw v)]
val from_raw_as_raw:
#a:Type
-> x:t a
-> Lemma (ensures (from_raw (as_raw x) == x))
[SMTPat (as_raw x)]
/// `v.(i)` accesses the ith element of v
unfold
let op_Array_Access
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
: Tot a
= (as_raw x).[i]
/// `v.(i) <- x` is a new t-vector that differs from v only at i
unfold
let op_Array_Assignment
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
(v:a) | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val op_Array_Assignment (#a: Type) (x: t a) (i: index_t (as_raw x)) (v: a) : Tot (t a) | [] | FStar.Vector.Base.op_Array_Assignment | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Vector.Base.t a -> i: FStar.Vector.Base.index_t (FStar.Vector.Base.as_raw x) -> v: a
-> FStar.Vector.Base.t a | {
"end_col": 34,
"end_line": 323,
"start_col": 4,
"start_line": 323
} |
Prims.GTot | val raw_length (#a: Type) (#l: len_t) (v: raw a l) : GTot nat | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l | val raw_length (#a: Type) (#l: len_t) (v: raw a l) : GTot nat
let raw_length (#a: Type) (#l: len_t) (v: raw a l) : GTot nat = | false | null | false | U32.v l | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"sometrivial"
] | [
"FStar.Vector.Base.len_t",
"FStar.Vector.Base.raw",
"FStar.UInt32.v",
"Prims.nat"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val raw_length (#a: Type) (#l: len_t) (v: raw a l) : GTot nat | [] | FStar.Vector.Base.raw_length | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: FStar.Vector.Base.raw a l -> Prims.GTot Prims.nat | {
"end_col": 68,
"end_line": 82,
"start_col": 61,
"start_line": 82
} |
Prims.Tot | val length (#a: Type) (x: t a) : nat | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length (#a:Type) (x:t a) : nat = U32.v (len x) | val length (#a: Type) (x: t a) : nat
let length (#a: Type) (x: t a) : nat = | false | null | false | U32.v (len x) | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.t",
"FStar.UInt32.v",
"FStar.Vector.Base.len",
"Prims.nat"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a
/// `v.[i]` is shorthand for `index v i`
unfold let op_String_Access #a #l = index #a #l
/// `update v i x`:
/// - a new vector that differs from `v` only at index `i`, where it contains `x`.
/// - Incurs a full copy in KaRaMeL
/// - In OCaml, the new vector shares as much as possible with `v`
val update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Tot (raw a l)
/// `v.[i] <- x` is shorthand for `update v i x`
unfold let op_String_Assignment #a #l = update #a #l
/// `append v1 v2`:
/// - requires proving that the sum of the lengths of v1 and v2 still fit in a u32
/// - Incurs a full copy in KaRaMeL
/// - Amortized constant time in OCaml
val append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Tot (raw a U32.(l1 +^ l2))
/// `v1 @| v2`: shorthand for `append v1 v2`
unfold let (@|) #a #l1 #l2 = append #a #l1 #l2
/// `sub v i j`:
/// - the sub-vector of `v` starting from index `i` up to, but not including, `j`
/// - Constant time in KaRaMeL (just an addition on a pointer)
/// - Worst-case (log l) time in OCaml
val sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Tot (raw a U32.(j -^ i))
////////////////////////////////////////////////////////////////////////////////
/// Lemmas about the basic operations, all rather boring
/// -- Each is just a lifting specifying the corresponding operation on seq
////////////////////////////////////////////////////////////////////////////////
val reveal_init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Lemma
(ensures (reveal (init l contents) == Seq.init (U32.v l) contents))
[SMTPat (init l contents)]
val reveal_index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Lemma
(ensures (v.[i] == Seq.index (reveal v) (U32.v i)))
[SMTPat (v.[i])]
val reveal_update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Lemma
(ensures (reveal (v.[i] <- x) == Seq.upd (reveal v) (U32.v i) x))
[SMTPat (v.[i] <- x)]
val reveal_append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Lemma
(ensures (reveal (v1 @| v2) == Seq.append (reveal v1) (reveal v2)))
[SMTPat (v1 @| v2)]
val reveal_sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Lemma
(ensures (reveal (sub v i j) == S.slice (reveal v) (U32.v i) (U32.v j)))
[SMTPat (sub v i j)]
////////////////////////////////////////////////////////////////////////////////
/// Now, we have `Vector.Base.t`, abstractly, a raw vector paired with its u32 length
////////////////////////////////////////////////////////////////////////////////
val t:
a:Type u#a
-> Type u#a
/// Unlike raw vectors, t-vectors support decidable equality
val t_has_eq:
a:Type u#a
-> Lemma
(requires (hasEq a))
(ensures (hasEq (t a)))
[SMTPat (hasEq (t a))]
/// The length of a t-vector is a dynamically computable u32
val len:
#a:Type
-> t a
-> len_t
/// A convenience to access the length of a t-vector as a nat | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val length (#a: Type) (x: t a) : nat | [] | FStar.Vector.Base.length | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Vector.Base.t a -> Prims.nat | {
"end_col": 50,
"end_line": 277,
"start_col": 37,
"start_line": 277
} |
Prims.Tot | val op_At_At (#a: Type) (x1: t a) (x2: t a {UInt.size (length x1 + length x2) U32.n}) : Tot (t a) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let (@@)
(#a:Type)
(x1:t a)
(x2:t a{UInt.size (length x1 + length x2) U32.n})
: Tot (t a)
= from_raw (as_raw x1 @| as_raw x2) | val op_At_At (#a: Type) (x1: t a) (x2: t a {UInt.size (length x1 + length x2) U32.n}) : Tot (t a)
let op_At_At (#a: Type) (x1: t a) (x2: t a {UInt.size (length x1 + length x2) U32.n}) : Tot (t a) = | false | null | false | from_raw (as_raw x1 @| as_raw x2) | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.t",
"FStar.UInt.size",
"Prims.op_Addition",
"FStar.Vector.Base.length",
"FStar.UInt32.n",
"FStar.Vector.Base.from_raw",
"FStar.UInt32.add",
"FStar.Vector.Base.len",
"FStar.Vector.Base.op_At_Bar",
"FStar.Vector.Base.as_raw"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a
/// `v.[i]` is shorthand for `index v i`
unfold let op_String_Access #a #l = index #a #l
/// `update v i x`:
/// - a new vector that differs from `v` only at index `i`, where it contains `x`.
/// - Incurs a full copy in KaRaMeL
/// - In OCaml, the new vector shares as much as possible with `v`
val update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Tot (raw a l)
/// `v.[i] <- x` is shorthand for `update v i x`
unfold let op_String_Assignment #a #l = update #a #l
/// `append v1 v2`:
/// - requires proving that the sum of the lengths of v1 and v2 still fit in a u32
/// - Incurs a full copy in KaRaMeL
/// - Amortized constant time in OCaml
val append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Tot (raw a U32.(l1 +^ l2))
/// `v1 @| v2`: shorthand for `append v1 v2`
unfold let (@|) #a #l1 #l2 = append #a #l1 #l2
/// `sub v i j`:
/// - the sub-vector of `v` starting from index `i` up to, but not including, `j`
/// - Constant time in KaRaMeL (just an addition on a pointer)
/// - Worst-case (log l) time in OCaml
val sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Tot (raw a U32.(j -^ i))
////////////////////////////////////////////////////////////////////////////////
/// Lemmas about the basic operations, all rather boring
/// -- Each is just a lifting specifying the corresponding operation on seq
////////////////////////////////////////////////////////////////////////////////
val reveal_init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Lemma
(ensures (reveal (init l contents) == Seq.init (U32.v l) contents))
[SMTPat (init l contents)]
val reveal_index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Lemma
(ensures (v.[i] == Seq.index (reveal v) (U32.v i)))
[SMTPat (v.[i])]
val reveal_update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Lemma
(ensures (reveal (v.[i] <- x) == Seq.upd (reveal v) (U32.v i) x))
[SMTPat (v.[i] <- x)]
val reveal_append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Lemma
(ensures (reveal (v1 @| v2) == Seq.append (reveal v1) (reveal v2)))
[SMTPat (v1 @| v2)]
val reveal_sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Lemma
(ensures (reveal (sub v i j) == S.slice (reveal v) (U32.v i) (U32.v j)))
[SMTPat (sub v i j)]
////////////////////////////////////////////////////////////////////////////////
/// Now, we have `Vector.Base.t`, abstractly, a raw vector paired with its u32 length
////////////////////////////////////////////////////////////////////////////////
val t:
a:Type u#a
-> Type u#a
/// Unlike raw vectors, t-vectors support decidable equality
val t_has_eq:
a:Type u#a
-> Lemma
(requires (hasEq a))
(ensures (hasEq (t a)))
[SMTPat (hasEq (t a))]
/// The length of a t-vector is a dynamically computable u32
val len:
#a:Type
-> t a
-> len_t
/// A convenience to access the length of a t-vector as a nat
[@@"deprecated: this will be moved to the ghost effect"]
let length (#a:Type) (x:t a) : nat = U32.v (len x)
/// Access the underlying raw vector
val as_raw:
#a:Type
-> x:t a
-> raw a (len x)
/// Promote a raw vector
val from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> x:t a{len x = l}
/// as_raw and from_raw are mutual inverses
val as_raw_from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (as_raw (from_raw v) == v))
[SMTPat (from_raw v)]
val from_raw_as_raw:
#a:Type
-> x:t a
-> Lemma (ensures (from_raw (as_raw x) == x))
[SMTPat (as_raw x)]
/// `v.(i)` accesses the ith element of v
unfold
let op_Array_Access
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
: Tot a
= (as_raw x).[i]
/// `v.(i) <- x` is a new t-vector that differs from v only at i
unfold
let op_Array_Assignment
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
(v:a)
: Tot (t a)
= from_raw ((as_raw x).[i] <- v)
/// `v1 @@ v2`: appending t-vectors
unfold
let (@@)
(#a:Type)
(x1:t a)
(x2:t a{UInt.size (length x1 + length x2) U32.n}) | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val op_At_At (#a: Type) (x1: t a) (x2: t a {UInt.size (length x1 + length x2) U32.n}) : Tot (t a) | [] | FStar.Vector.Base.op_At_At | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
x1: FStar.Vector.Base.t a ->
x2:
FStar.Vector.Base.t a
{FStar.UInt.size (FStar.Vector.Base.length x1 + FStar.Vector.Base.length x2) FStar.UInt32.n}
-> FStar.Vector.Base.t a | {
"end_col": 37,
"end_line": 332,
"start_col": 4,
"start_line": 332
} |
Prims.Tot | val slice (#a: Type) (x: t a) (i: len_t) (j: len_t{let open U32 in v i <= v j /\ v j <= length x})
: Tot (t a) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let slice
(#a:Type)
(x:t a)
(i:len_t)
(j:len_t{U32.(v i <= v j /\ v j <= length x)})
: Tot (t a)
= from_raw (sub (as_raw x) i j) | val slice (#a: Type) (x: t a) (i: len_t) (j: len_t{let open U32 in v i <= v j /\ v j <= length x})
: Tot (t a)
let slice (#a: Type) (x: t a) (i: len_t) (j: len_t{let open U32 in v i <= v j /\ v j <= length x})
: Tot (t a) = | false | null | false | from_raw (sub (as_raw x) i j) | {
"checked_file": "FStar.Vector.Base.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Vector.Base.fsti"
} | [
"total"
] | [
"FStar.Vector.Base.t",
"FStar.Vector.Base.len_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Vector.Base.length",
"FStar.Vector.Base.from_raw",
"FStar.UInt32.op_Subtraction_Hat",
"FStar.Vector.Base.sub",
"FStar.Vector.Base.len",
"FStar.Vector.Base.as_raw"
] | [] | (*
Copyright 2008-2017 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.
*)
(*
A library for vectors, i.e., immutable arrays, whose length is
representable by a machine integer, FStar.UInt32.t.
This is closely related to FStar.Seq, with the following main
differences:
The type `raw a l`: A raw vector
1. Raw vectors receive special treatment during extraction,
especially by KaRaMeL, which extracts a vector to a raw C
pointer. When extracting to OCaml, a `raw a l` is a
`Batteries.Vect t a`
2. The length of a vector is representable in a U32.t
3. The interface is designed around a length-indexed type: this
enables the compilation to raw pointers, since this ensures
that all functions that manipulate vectors always have a U32
variable describing that vector's length in scope.
A length-indexed interface is also suitable for clients for whom
proving properties about the length is a primary concern: the
signatures in this interface carry intrinsic proofs about length
properties, simplifying proof obligations in client code.
4. Raw vectors lack decidable equality (since that cannot be
implemented given the representation choice in KaRaMeL)
The type `t a`: A dynamically sized vector
1. Conceptually, a `t a` is a pair of a `len:U32.t` and a `raw a
len`. They are implemented as such by KaRaMeL. When extracting
to OCaml, `t a` is identical to `raw a _`, i.e., it is still
extracted to a `Batteries.Vect.t a`
2. Unlike raw vectors, `t a` supports decidable equality when it
is supported by `a`. This is the main reason `t a` is provided
at an abstract type, rather than being exposed as a pair of a
U32 and a raw vector, since the latter does not support
decidable equality.
@summary Immutable vectors whose length is less than `pow2 32`
*)
module FStar.Vector.Base
module U32 = FStar.UInt32
module S = FStar.Seq
////////////////////////////////////////////////////////////////////////////////
/// The basic model of raw vectors as u32-length sequences
////////////////////////////////////////////////////////////////////////////////
/// The length of a vector fits in 32 bits
let len_t = U32.t
/// A raw vector.
/// - `vector a n` is extracted to an `a*` in C by KaRaMeL
/// - Does not support decidable equality
val raw ([@@@strictly_positive] a:Type u#a)
(l:len_t)
: Type u#a
/// A convenience to use `nat` for the length of vector in specs and proofs
let raw_length (#a:Type) (#l:len_t) (v:raw a l) : GTot nat = U32.v l
(**
Abstractly, a `vec a l` is just a sequence whose length is `U32.v l`.
`reveal` and `hide` build an isomorphism establishing this
**)
val reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> GTot (s:S.seq a{S.length s = raw_length v})
val hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> GTot (raw a (U32.uint_to_t (S.length s)))
val hide_reveal:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (hide (reveal v) == v))
[SMTPat (reveal v)]
val reveal_hide:
#a:Type
-> s:S.seq a{S.length s < pow2 32}
-> Lemma (ensures (reveal (hide s) == s))
[SMTPat (hide s)]
/// Extensional equality for vectors
let equal (#a:Type) (#l:len_t) (v1:raw a l) (v2:raw a l) =
Seq.equal (reveal v1) (reveal v2)
/// Extensional equality can be used to prove syntactic equality
val extensionality:
#a:Type
-> #l:len_t
-> v1:raw a l
-> v2:raw a l
-> Lemma (requires (equal v1 v2))
(ensures (v1 == v2))
////////////////////////////////////////////////////////////////////////////////
/// end of the basic model
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// A small set of basic operations on raw vectors, corresponding to the operations
/// on sequences. Other operations can be derived from these, as we do for seq.
/// -- init, index, update, append, slice
////////////////////////////////////////////////////////////////////////////////
/// `index_t v`: is the type of a within-bounds index of `v`
let index_t (#a:Type) (#l:len_t) (v:raw a l) =
m:len_t{U32.v m < U32.v l}
/// `init l contents`:
/// initialize an `l`-sized vector using `contents i` for the `i`th element
val init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Tot (raw a l)
/// `index v i`: get the `i`th element of `v`
val index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Tot a
/// `v.[i]` is shorthand for `index v i`
unfold let op_String_Access #a #l = index #a #l
/// `update v i x`:
/// - a new vector that differs from `v` only at index `i`, where it contains `x`.
/// - Incurs a full copy in KaRaMeL
/// - In OCaml, the new vector shares as much as possible with `v`
val update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Tot (raw a l)
/// `v.[i] <- x` is shorthand for `update v i x`
unfold let op_String_Assignment #a #l = update #a #l
/// `append v1 v2`:
/// - requires proving that the sum of the lengths of v1 and v2 still fit in a u32
/// - Incurs a full copy in KaRaMeL
/// - Amortized constant time in OCaml
val append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Tot (raw a U32.(l1 +^ l2))
/// `v1 @| v2`: shorthand for `append v1 v2`
unfold let (@|) #a #l1 #l2 = append #a #l1 #l2
/// `sub v i j`:
/// - the sub-vector of `v` starting from index `i` up to, but not including, `j`
/// - Constant time in KaRaMeL (just an addition on a pointer)
/// - Worst-case (log l) time in OCaml
val sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Tot (raw a U32.(j -^ i))
////////////////////////////////////////////////////////////////////////////////
/// Lemmas about the basic operations, all rather boring
/// -- Each is just a lifting specifying the corresponding operation on seq
////////////////////////////////////////////////////////////////////////////////
val reveal_init:
#a:Type
-> l:len_t
-> contents: (i:nat { i < U32.v l } -> Tot a)
-> Lemma
(ensures (reveal (init l contents) == Seq.init (U32.v l) contents))
[SMTPat (init l contents)]
val reveal_index:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> Lemma
(ensures (v.[i] == Seq.index (reveal v) (U32.v i)))
[SMTPat (v.[i])]
val reveal_update:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:index_t v
-> x:a
-> Lemma
(ensures (reveal (v.[i] <- x) == Seq.upd (reveal v) (U32.v i) x))
[SMTPat (v.[i] <- x)]
val reveal_append:
#a:Type
-> #l1:len_t
-> #l2:len_t
-> v1:raw a l1
-> v2:raw a l2{UInt.size U32.(v l1 + v l2) U32.n}
-> Lemma
(ensures (reveal (v1 @| v2) == Seq.append (reveal v1) (reveal v2)))
[SMTPat (v1 @| v2)]
val reveal_sub:
#a:Type
-> #l:len_t
-> v:raw a l
-> i:len_t
-> j:len_t{U32.(v i <= v j /\ v j <= v l)}
-> Lemma
(ensures (reveal (sub v i j) == S.slice (reveal v) (U32.v i) (U32.v j)))
[SMTPat (sub v i j)]
////////////////////////////////////////////////////////////////////////////////
/// Now, we have `Vector.Base.t`, abstractly, a raw vector paired with its u32 length
////////////////////////////////////////////////////////////////////////////////
val t:
a:Type u#a
-> Type u#a
/// Unlike raw vectors, t-vectors support decidable equality
val t_has_eq:
a:Type u#a
-> Lemma
(requires (hasEq a))
(ensures (hasEq (t a)))
[SMTPat (hasEq (t a))]
/// The length of a t-vector is a dynamically computable u32
val len:
#a:Type
-> t a
-> len_t
/// A convenience to access the length of a t-vector as a nat
[@@"deprecated: this will be moved to the ghost effect"]
let length (#a:Type) (x:t a) : nat = U32.v (len x)
/// Access the underlying raw vector
val as_raw:
#a:Type
-> x:t a
-> raw a (len x)
/// Promote a raw vector
val from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> x:t a{len x = l}
/// as_raw and from_raw are mutual inverses
val as_raw_from_raw:
#a:Type
-> #l:len_t
-> v:raw a l
-> Lemma (ensures (as_raw (from_raw v) == v))
[SMTPat (from_raw v)]
val from_raw_as_raw:
#a:Type
-> x:t a
-> Lemma (ensures (from_raw (as_raw x) == x))
[SMTPat (as_raw x)]
/// `v.(i)` accesses the ith element of v
unfold
let op_Array_Access
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
: Tot a
= (as_raw x).[i]
/// `v.(i) <- x` is a new t-vector that differs from v only at i
unfold
let op_Array_Assignment
(#a:Type)
(x:t a)
(i:index_t (as_raw x))
(v:a)
: Tot (t a)
= from_raw ((as_raw x).[i] <- v)
/// `v1 @@ v2`: appending t-vectors
unfold
let (@@)
(#a:Type)
(x1:t a)
(x2:t a{UInt.size (length x1 + length x2) U32.n})
: Tot (t a)
= from_raw (as_raw x1 @| as_raw x2)
/// `slice v i j`:
/// the sub-vector of `v` starting from index `i` up to, but not including, `j`
unfold
let slice
(#a:Type)
(x:t a)
(i:len_t)
(j:len_t{U32.(v i <= v j /\ v j <= length x)}) | false | false | FStar.Vector.Base.fsti | {
"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"
} | null | val slice (#a: Type) (x: t a) (i: len_t) (j: len_t{let open U32 in v i <= v j /\ v j <= length x})
: Tot (t a) | [] | FStar.Vector.Base.slice | {
"file_name": "ulib/FStar.Vector.Base.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
x: FStar.Vector.Base.t a ->
i: FStar.Vector.Base.len_t ->
j:
FStar.Vector.Base.len_t
{FStar.UInt32.v i <= FStar.UInt32.v j /\ FStar.UInt32.v j <= FStar.Vector.Base.length x}
-> FStar.Vector.Base.t a | {
"end_col": 33,
"end_line": 343,
"start_col": 4,
"start_line": 343
} |
Prims.GTot | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put32_128 = opaque_make put32_128_def | let put32_128 = | false | null | false | opaque_make put32_128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.t",
"Vale.Interop.Views.put32_128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) =
seq_nat8_to_seq_uint8 (le_quad32_to_bytes a)
[@"opaque_to_smt"] let put128 = opaque_make put128_def
irreducible let put128_reveal = opaque_revealer (`%put128) put128 put128_def
val inverses128 (u:unit) : Lemma (DV.inverses get128 put128)
let up_view128 = inverses128 (); BV.View 16 get128 put128
let down_view128 = inverses128 (); DV.View 16 put128 get128
let nat32s_to_nat128 (v1 v2 v3 v4: nat32): nat128 =
v1 + v2 * 0x100000000 + v3 * 0x1000000000000 + v4 * 0x1000000000000000000000000
module U32 = FStar.UInt32
let get32_128_def (s: Seq.lseq U32.t 4) : quad32 =
seq_to_four_LE (seq_map UInt32.v s)
[@"opaque_to_smt"] let get32_128 = opaque_make get32_128_def
irreducible let get32_128_reveal = opaque_revealer (`%get32_128) get32_128 get32_128_def
let put32_128_def (a:quad32) : GTot (Seq.lseq U32.t 4) = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put32_128 : _: Vale.Def.Types_s.quad32 -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt32.t 4) | [] | Vale.Interop.Views.put32_128 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Vale.Def.Types_s.quad32 -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt32.t 4) | {
"end_col": 60,
"end_line": 110,
"start_col": 35,
"start_line": 110
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get8_reveal = opaque_revealer (`%get8) get8 get8_def | let get8_reveal = | false | null | true | opaque_revealer (`%get8) get8 get8_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.get8",
"Vale.Interop.Views.get8_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0 | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get8_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get8 == Vale.Interop.Views.get8_def) | [] | Vale.Interop.Views.get8_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get8 == Vale.Interop.Views.get8_def) | {
"end_col": 68,
"end_line": 18,
"start_col": 30,
"start_line": 18
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put64_reveal = opaque_revealer (`%put64) put64 put64_def | let put64_reveal = | false | null | true | opaque_revealer (`%put64) put64 put64_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.UInt64.t",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put64",
"Vale.Interop.Views.put64_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a)) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put64_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put64 == Vale.Interop.Views.put64_def) | [] | Vale.Interop.Views.put64_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put64 == Vale.Interop.Views.put64_def) | {
"end_col": 72,
"end_line": 76,
"start_col": 31,
"start_line": 76
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get32_128 = opaque_make get32_128_def | let get32_128 = | false | null | false | opaque_make get32_128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.t",
"Vale.Def.Types_s.quad32",
"Vale.Interop.Views.get32_128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) =
seq_nat8_to_seq_uint8 (le_quad32_to_bytes a)
[@"opaque_to_smt"] let put128 = opaque_make put128_def
irreducible let put128_reveal = opaque_revealer (`%put128) put128 put128_def
val inverses128 (u:unit) : Lemma (DV.inverses get128 put128)
let up_view128 = inverses128 (); BV.View 16 get128 put128
let down_view128 = inverses128 (); DV.View 16 put128 get128
let nat32s_to_nat128 (v1 v2 v3 v4: nat32): nat128 =
v1 + v2 * 0x100000000 + v3 * 0x1000000000000 + v4 * 0x1000000000000000000000000
module U32 = FStar.UInt32
let get32_128_def (s: Seq.lseq U32.t 4) : quad32 = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get32_128 : _: FStar.Seq.Properties.lseq FStar.UInt32.t 4 -> Vale.Def.Types_s.quad32 | [] | Vale.Interop.Views.get32_128 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.Seq.Properties.lseq FStar.UInt32.t 4 -> Vale.Def.Types_s.quad32 | {
"end_col": 60,
"end_line": 105,
"start_col": 35,
"start_line": 105
} |
|
Prims.GTot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put32 = opaque_make put32_def | let put32 = | false | null | false | opaque_make put32_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.UInt32.t",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put32_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put32 : _: FStar.UInt32.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 4) | [] | Vale.Interop.Views.put32 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.UInt32.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 4) | {
"end_col": 52,
"end_line": 60,
"start_col": 31,
"start_line": 60
} |
|
Prims.GTot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put64 = opaque_make put64_def | let put64 = | false | null | false | opaque_make put64_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.UInt64.t",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put64_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put64 : _: FStar.UInt64.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 8) | [] | Vale.Interop.Views.put64 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.UInt64.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 8) | {
"end_col": 52,
"end_line": 75,
"start_col": 31,
"start_line": 75
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get32 = opaque_make get32_def | let get32 = | false | null | false | opaque_make get32_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.UInt32.t",
"Vale.Interop.Views.get32_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get32 : _: FStar.Seq.Properties.lseq FStar.UInt8.t 4 -> FStar.UInt32.t | [] | Vale.Interop.Views.get32 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.Seq.Properties.lseq FStar.UInt8.t 4 -> FStar.UInt32.t | {
"end_col": 52,
"end_line": 55,
"start_col": 31,
"start_line": 55
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get8 = opaque_make get8_def | let get8 = | false | null | false | opaque_make get8_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.get8_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8 | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get8 : _: FStar.Seq.Properties.lseq FStar.UInt8.t 1 -> FStar.UInt8.t | [] | Vale.Interop.Views.get8 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.Seq.Properties.lseq FStar.UInt8.t 1 -> FStar.UInt8.t | {
"end_col": 50,
"end_line": 17,
"start_col": 30,
"start_line": 17
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get16 = opaque_make get16_def | let get16 = | false | null | false | opaque_make get16_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.UInt16.t",
"Vale.Interop.Views.get16_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100 | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get16 : _: FStar.Seq.Properties.lseq FStar.UInt8.t 2 -> FStar.UInt16.t | [] | Vale.Interop.Views.get16 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.Seq.Properties.lseq FStar.UInt8.t 2 -> FStar.UInt16.t | {
"end_col": 52,
"end_line": 35,
"start_col": 31,
"start_line": 35
} |
|
Prims.GTot | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put8 = opaque_make put8_def | let put8 = | false | null | false | opaque_make put8_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.UInt8.t",
"FStar.Seq.Properties.lseq",
"Vale.Interop.Views.put8_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put8 : _: FStar.UInt8.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 1) | [] | Vale.Interop.Views.put8 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.UInt8.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 1) | {
"end_col": 50,
"end_line": 23,
"start_col": 30,
"start_line": 23
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get64 = opaque_make get64_def | let get64 = | false | null | false | opaque_make get64_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.UInt64.t",
"Vale.Interop.Views.get64_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get64 : _: FStar.Seq.Properties.lseq FStar.UInt8.t 8 -> FStar.UInt64.t | [] | Vale.Interop.Views.get64 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.Seq.Properties.lseq FStar.UInt8.t 8 -> FStar.UInt64.t | {
"end_col": 52,
"end_line": 70,
"start_col": 31,
"start_line": 70
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get32_reveal = opaque_revealer (`%get32) get32 get32_def | let get32_reveal = | false | null | true | opaque_revealer (`%get32) get32 get32_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.UInt32.t",
"Vale.Interop.Views.get32",
"Vale.Interop.Views.get32_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s))) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get32_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get32 == Vale.Interop.Views.get32_def) | [] | Vale.Interop.Views.get32_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get32 == Vale.Interop.Views.get32_def) | {
"end_col": 72,
"end_line": 56,
"start_col": 31,
"start_line": 56
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put32_reveal = opaque_revealer (`%put32) put32 put32_def | let put32_reveal = | false | null | true | opaque_revealer (`%put32) put32 put32_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.UInt32.t",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put32",
"Vale.Interop.Views.put32_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x))) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put32_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put32 == Vale.Interop.Views.put32_def) | [] | Vale.Interop.Views.put32_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put32 == Vale.Interop.Views.put32_def) | {
"end_col": 72,
"end_line": 61,
"start_col": 31,
"start_line": 61
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get128_reveal = opaque_revealer (`%get128) get128 get128_def | let get128_reveal = | false | null | true | opaque_revealer (`%get128) get128 get128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Def.Types_s.quad32",
"Vale.Interop.Views.get128",
"Vale.Interop.Views.get128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get128_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get128 == Vale.Interop.Views.get128_def) | [] | Vale.Interop.Views.get128_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get128 == Vale.Interop.Views.get128_def) | {
"end_col": 76,
"end_line": 86,
"start_col": 32,
"start_line": 86
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get32_128_reveal = opaque_revealer (`%get32_128) get32_128 get32_128_def | let get32_128_reveal = | false | null | true | opaque_revealer (`%get32_128) get32_128 get32_128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.t",
"Vale.Def.Types_s.quad32",
"Vale.Interop.Views.get32_128",
"Vale.Interop.Views.get32_128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) =
seq_nat8_to_seq_uint8 (le_quad32_to_bytes a)
[@"opaque_to_smt"] let put128 = opaque_make put128_def
irreducible let put128_reveal = opaque_revealer (`%put128) put128 put128_def
val inverses128 (u:unit) : Lemma (DV.inverses get128 put128)
let up_view128 = inverses128 (); BV.View 16 get128 put128
let down_view128 = inverses128 (); DV.View 16 put128 get128
let nat32s_to_nat128 (v1 v2 v3 v4: nat32): nat128 =
v1 + v2 * 0x100000000 + v3 * 0x1000000000000 + v4 * 0x1000000000000000000000000
module U32 = FStar.UInt32
let get32_128_def (s: Seq.lseq U32.t 4) : quad32 =
seq_to_four_LE (seq_map UInt32.v s) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get32_128_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.Interop.Views.get32_128 == Vale.Interop.Views.get32_128_def) | [] | Vale.Interop.Views.get32_128_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.Interop.Views.get32_128 == Vale.Interop.Views.get32_128_def) | {
"end_col": 88,
"end_line": 106,
"start_col": 35,
"start_line": 106
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get16_reveal = opaque_revealer (`%get16) get16 get16_def | let get16_reveal = | false | null | true | opaque_revealer (`%get16) get16 get16_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.UInt16.t",
"Vale.Interop.Views.get16",
"Vale.Interop.Views.get16_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get16_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get16 == Vale.Interop.Views.get16_def) | [] | Vale.Interop.Views.get16_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get16 == Vale.Interop.Views.get16_def) | {
"end_col": 72,
"end_line": 36,
"start_col": 31,
"start_line": 36
} |
|
Prims.GTot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put128 = opaque_make put128_def | let put128 = | false | null | false | opaque_make put128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put128 : _: Vale.Def.Types_s.quad32 -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 16) | [] | Vale.Interop.Views.put128 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Vale.Def.Types_s.quad32 -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 16) | {
"end_col": 54,
"end_line": 90,
"start_col": 32,
"start_line": 90
} |
|
Prims.GTot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put16 = opaque_make put16_def | let put16 = | false | null | false | opaque_make put16_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.UInt16.t",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put16_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put16 : _: FStar.UInt16.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 2) | [] | Vale.Interop.Views.put16 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.UInt16.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 2) | {
"end_col": 52,
"end_line": 45,
"start_col": 31,
"start_line": 45
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get128 = opaque_make get128_def | let get128 = | false | null | false | opaque_make get128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"Vale.Def.Opaque_s.opaque_make",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Def.Types_s.quad32",
"Vale.Interop.Views.get128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) = | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get128 : _: FStar.Seq.Properties.lseq FStar.UInt8.t 16 -> Vale.Def.Types_s.quad32 | [] | Vale.Interop.Views.get128 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: FStar.Seq.Properties.lseq FStar.UInt8.t 16 -> Vale.Def.Types_s.quad32 | {
"end_col": 54,
"end_line": 85,
"start_col": 32,
"start_line": 85
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put16_reveal = opaque_revealer (`%put16) put16 put16_def | let put16_reveal = | false | null | true | opaque_revealer (`%put16) put16 put16_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.UInt16.t",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put16",
"Vale.Interop.Views.put16_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put16_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put16 == Vale.Interop.Views.put16_def) | [] | Vale.Interop.Views.put16_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put16 == Vale.Interop.Views.put16_def) | {
"end_col": 72,
"end_line": 46,
"start_col": 31,
"start_line": 46
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put8_reveal = opaque_revealer (`%put8) put8 put8_def | let put8_reveal = | false | null | true | opaque_revealer (`%put8) put8 put8_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.UInt8.t",
"FStar.Seq.Properties.lseq",
"Vale.Interop.Views.put8",
"Vale.Interop.Views.put8_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put8_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put8 == Vale.Interop.Views.put8_def) | [] | Vale.Interop.Views.put8_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put8 == Vale.Interop.Views.put8_def) | {
"end_col": 68,
"end_line": 24,
"start_col": 30,
"start_line": 24
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put32_128_reveal = opaque_revealer (`%put32_128) put32_128 put32_128_def | let put32_128_reveal = | false | null | true | opaque_revealer (`%put32_128) put32_128 put32_128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.t",
"Vale.Interop.Views.put32_128",
"Vale.Interop.Views.put32_128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) =
seq_nat8_to_seq_uint8 (le_quad32_to_bytes a)
[@"opaque_to_smt"] let put128 = opaque_make put128_def
irreducible let put128_reveal = opaque_revealer (`%put128) put128 put128_def
val inverses128 (u:unit) : Lemma (DV.inverses get128 put128)
let up_view128 = inverses128 (); BV.View 16 get128 put128
let down_view128 = inverses128 (); DV.View 16 put128 get128
let nat32s_to_nat128 (v1 v2 v3 v4: nat32): nat128 =
v1 + v2 * 0x100000000 + v3 * 0x1000000000000 + v4 * 0x1000000000000000000000000
module U32 = FStar.UInt32
let get32_128_def (s: Seq.lseq U32.t 4) : quad32 =
seq_to_four_LE (seq_map UInt32.v s)
[@"opaque_to_smt"] let get32_128 = opaque_make get32_128_def
irreducible let get32_128_reveal = opaque_revealer (`%get32_128) get32_128 get32_128_def
let put32_128_def (a:quad32) : GTot (Seq.lseq U32.t 4) =
seq_map UInt32.uint_to_t (four_to_seq_LE a) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put32_128_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.Interop.Views.put32_128 == Vale.Interop.Views.put32_128_def) | [] | Vale.Interop.Views.put32_128_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.Interop.Views.put32_128 == Vale.Interop.Views.put32_128_def) | {
"end_col": 88,
"end_line": 111,
"start_col": 35,
"start_line": 111
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put128_reveal = opaque_revealer (`%put128) put128 put128_def | let put128_reveal = | false | null | true | opaque_revealer (`%put128) put128 put128_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Interop.Views.put128",
"Vale.Interop.Views.put128_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) =
seq_nat8_to_seq_uint8 (le_quad32_to_bytes a) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put128_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put128 == Vale.Interop.Views.put128_def) | [] | Vale.Interop.Views.put128_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.put128 == Vale.Interop.Views.put128_def) | {
"end_col": 76,
"end_line": 91,
"start_col": 32,
"start_line": 91
} |
|
FStar.Pervasives.Lemma | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get64_reveal = opaque_revealer (`%get64) get64 get64_def | let get64_reveal = | false | null | true | opaque_revealer (`%get64) get64 get64_def | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"lemma"
] | [
"Vale.Def.Opaque_s.opaque_revealer",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.UInt64.t",
"Vale.Interop.Views.get64",
"Vale.Interop.Views.get64_def"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s)) | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get64_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get64 == Vale.Interop.Views.get64_def) | [] | Vale.Interop.Views.get64_reveal | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures Vale.Interop.Views.get64 == Vale.Interop.Views.get64_def) | {
"end_col": 72,
"end_line": 71,
"start_col": 31,
"start_line": 71
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let up_view8 = inverses8 (); BV.View 1 get8 put8 | let up_view8 = | false | null | false | inverses8 ();
BV.View 1 get8 put8 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Up.View",
"FStar.UInt8.t",
"Vale.Interop.Views.get8",
"Vale.Interop.Views.put8",
"Prims.unit",
"Vale.Interop.Views.inverses8"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val up_view8 : LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt8.t | [] | Vale.Interop.Views.up_view8 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt8.t | {
"end_col": 48,
"end_line": 28,
"start_col": 15,
"start_line": 28
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let down_view8 = inverses8 (); DV.View 1 put8 get8 | let down_view8 = | false | null | false | inverses8 ();
DV.View 1 put8 get8 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Down.View",
"FStar.UInt8.t",
"Vale.Interop.Views.put8",
"Vale.Interop.Views.get8",
"Prims.unit",
"Vale.Interop.Views.inverses8"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val down_view8 : LowStar.BufferView.Down.view FStar.UInt8.t FStar.UInt8.t | [] | Vale.Interop.Views.down_view8 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Down.view FStar.UInt8.t FStar.UInt8.t | {
"end_col": 50,
"end_line": 29,
"start_col": 17,
"start_line": 29
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let down_view64 = inverses64 (); DV.View 8 put64 get64 | let down_view64 = | false | null | false | inverses64 ();
DV.View 8 put64 get64 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Down.View",
"FStar.UInt64.t",
"FStar.UInt8.t",
"Vale.Interop.Views.put64",
"Vale.Interop.Views.get64",
"Prims.unit",
"Vale.Interop.Views.inverses64"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val down_view64 : LowStar.BufferView.Down.view FStar.UInt64.t FStar.UInt8.t | [] | Vale.Interop.Views.down_view64 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Down.view FStar.UInt64.t FStar.UInt8.t | {
"end_col": 54,
"end_line": 81,
"start_col": 18,
"start_line": 81
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s) | let get128_def (s: Seq.lseq U8.t 16) = | false | null | false | le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s) | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"Vale.Def.Types_s.le_bytes_to_quad32",
"Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8",
"Vale.Def.Types_s.quad32"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64 | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get128_def : s: FStar.Seq.Properties.lseq FStar.UInt8.t 16 -> Vale.Def.Types_s.quad32 | [] | Vale.Interop.Views.get128_def | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: FStar.Seq.Properties.lseq FStar.UInt8.t 16 -> Vale.Def.Types_s.quad32 | {
"end_col": 46,
"end_line": 84,
"start_col": 2,
"start_line": 84
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0 | let get8_def (s: Seq.lseq U8.t 1) = | false | null | false | Seq.index s 0 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.Seq.Base.index"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8 | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get8_def : s: FStar.Seq.Properties.lseq FStar.UInt8.t 1 -> FStar.UInt8.t | [] | Vale.Interop.Views.get8_def | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: FStar.Seq.Properties.lseq FStar.UInt8.t 1 -> FStar.UInt8.t | {
"end_col": 48,
"end_line": 16,
"start_col": 35,
"start_line": 16
} |
|
Prims.GTot | val put64_def (a: UInt64.t) : GTot (Seq.lseq U8.t 8) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a)) | val put64_def (a: UInt64.t) : GTot (Seq.lseq U8.t 8)
let put64_def (a: UInt64.t) : GTot (Seq.lseq U8.t 8) = | false | null | false | seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a)) | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"FStar.UInt64.t",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8",
"Vale.Def.Types_s.le_nat64_to_bytes",
"FStar.UInt64.v",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put64_def (a: UInt64.t) : GTot (Seq.lseq U8.t 8) | [] | Vale.Interop.Views.put64_def | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: FStar.UInt64.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 8) | {
"end_col": 56,
"end_line": 74,
"start_col": 2,
"start_line": 74
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let up_view128 = inverses128 (); BV.View 16 get128 put128 | let up_view128 = | false | null | false | inverses128 ();
BV.View 16 get128 put128 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Up.View",
"FStar.UInt8.t",
"Vale.Def.Types_s.quad32",
"Vale.Interop.Views.get128",
"Vale.Interop.Views.put128",
"Prims.unit",
"Vale.Interop.Views.inverses128"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) =
seq_nat8_to_seq_uint8 (le_quad32_to_bytes a)
[@"opaque_to_smt"] let put128 = opaque_make put128_def
irreducible let put128_reveal = opaque_revealer (`%put128) put128 put128_def
val inverses128 (u:unit) : Lemma (DV.inverses get128 put128) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val up_view128 : LowStar.BufferView.Up.view FStar.UInt8.t Vale.Def.Types_s.quad32 | [] | Vale.Interop.Views.up_view128 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Up.view FStar.UInt8.t Vale.Def.Types_s.quad32 | {
"end_col": 57,
"end_line": 95,
"start_col": 17,
"start_line": 95
} |
|
Prims.GTot | val put16_def (x: UInt16.t) : GTot (Seq.lseq U8.t 2) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s | val put16_def (x: UInt16.t) : GTot (Seq.lseq U8.t 2)
let put16_def (x: UInt16.t) : GTot (Seq.lseq U8.t 2) = | false | null | false | let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"FStar.UInt16.t",
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"FStar.Seq.Base.upd",
"FStar.UInt8.uint_to_t",
"Prims.op_Modulus",
"Prims.int",
"Prims.op_Division",
"FStar.UInt.uint_t",
"FStar.UInt16.v",
"FStar.Seq.Base.create",
"FStar.Seq.Properties.lseq"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put16_def (x: UInt16.t) : GTot (Seq.lseq U8.t 2) | [] | Vale.Interop.Views.put16_def | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: FStar.UInt16.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 2) | {
"end_col": 3,
"end_line": 44,
"start_col": 53,
"start_line": 38
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let up_view16 = inverses16 (); BV.View 2 get16 put16 | let up_view16 = | false | null | false | inverses16 ();
BV.View 2 get16 put16 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Up.View",
"FStar.UInt8.t",
"FStar.UInt16.t",
"Vale.Interop.Views.get16",
"Vale.Interop.Views.put16",
"Prims.unit",
"Vale.Interop.Views.inverses16"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val up_view16 : LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt16.t | [] | Vale.Interop.Views.up_view16 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt16.t | {
"end_col": 52,
"end_line": 50,
"start_col": 16,
"start_line": 50
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let down_view32 = inverses32(); DV.View 4 put32 get32 | let down_view32 = | false | null | false | inverses32 ();
DV.View 4 put32 get32 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Down.View",
"FStar.UInt32.t",
"FStar.UInt8.t",
"Vale.Interop.Views.put32",
"Vale.Interop.Views.get32",
"Prims.unit",
"Vale.Interop.Views.inverses32"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val down_view32 : LowStar.BufferView.Down.view FStar.UInt32.t FStar.UInt8.t | [] | Vale.Interop.Views.down_view32 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Down.view FStar.UInt32.t FStar.UInt8.t | {
"end_col": 53,
"end_line": 66,
"start_col": 18,
"start_line": 66
} |
|
Prims.GTot | val put8_def (x: U8.t) : GTot (Seq.lseq U8.t 1) | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents | val put8_def (x: U8.t) : GTot (Seq.lseq U8.t 1)
let put8_def (x: U8.t) : GTot (Seq.lseq U8.t 1) = | false | null | false | let contents (i: nat{i < 1}) = x in
Seq.init 1 contents | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"sometrivial"
] | [
"FStar.UInt8.t",
"FStar.Seq.Base.init",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Properties.lseq"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val put8_def (x: U8.t) : GTot (Seq.lseq U8.t 1) | [] | Vale.Interop.Views.put8_def | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: FStar.UInt8.t -> Prims.GTot (FStar.Seq.Properties.lseq FStar.UInt8.t 1) | {
"end_col": 21,
"end_line": 22,
"start_col": 48,
"start_line": 20
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let down_view128 = inverses128 (); DV.View 16 put128 get128 | let down_view128 = | false | null | false | inverses128 ();
DV.View 16 put128 get128 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Down.View",
"Vale.Def.Types_s.quad32",
"FStar.UInt8.t",
"Vale.Interop.Views.put128",
"Vale.Interop.Views.get128",
"Prims.unit",
"Vale.Interop.Views.inverses128"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32
let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s))
[@"opaque_to_smt"] let get64 = opaque_make get64_def
irreducible let get64_reveal = opaque_revealer (`%get64) get64 get64_def
let put64_def (a:UInt64.t) : GTot (Seq.lseq U8.t 8) =
seq_nat8_to_seq_uint8 (le_nat64_to_bytes (UInt64.v a))
[@"opaque_to_smt"] let put64 = opaque_make put64_def
irreducible let put64_reveal = opaque_revealer (`%put64) put64 put64_def
val inverses64 (u:unit) : Lemma (DV.inverses get64 put64)
let up_view64 = inverses64 (); BV.View 8 get64 put64
let down_view64 = inverses64 (); DV.View 8 put64 get64
let get128_def (s:Seq.lseq U8.t 16) =
le_bytes_to_quad32 (seq_uint8_to_seq_nat8 s)
[@"opaque_to_smt"] let get128 = opaque_make get128_def
irreducible let get128_reveal = opaque_revealer (`%get128) get128 get128_def
let put128_def (a:quad32) : GTot (Seq.lseq U8.t 16) =
seq_nat8_to_seq_uint8 (le_quad32_to_bytes a)
[@"opaque_to_smt"] let put128 = opaque_make put128_def
irreducible let put128_reveal = opaque_revealer (`%put128) put128 put128_def
val inverses128 (u:unit) : Lemma (DV.inverses get128 put128) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val down_view128 : LowStar.BufferView.Down.view Vale.Def.Types_s.quad32 FStar.UInt8.t | [] | Vale.Interop.Views.down_view128 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Down.view Vale.Def.Types_s.quad32 FStar.UInt8.t | {
"end_col": 59,
"end_line": 96,
"start_col": 19,
"start_line": 96
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let up_view32 = inverses32(); BV.View 4 get32 put32 | let up_view32 = | false | null | false | inverses32 ();
BV.View 4 get32 put32 | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"LowStar.BufferView.Up.View",
"FStar.UInt8.t",
"FStar.UInt32.t",
"Vale.Interop.Views.get32",
"Vale.Interop.Views.put32",
"Prims.unit",
"Vale.Interop.Views.inverses32"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32) | false | true | Vale.Interop.Views.fsti | {
"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"
} | null | val up_view32 : LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt32.t | [] | Vale.Interop.Views.up_view32 | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | LowStar.BufferView.Up.view FStar.UInt8.t FStar.UInt32.t | {
"end_col": 51,
"end_line": 65,
"start_col": 16,
"start_line": 65
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_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": "LowStar.BufferView.Up",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get64_def (s:Seq.lseq U8.t 8) =
UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s)) | let get64_def (s: Seq.lseq U8.t 8) = | false | null | false | UInt64.uint_to_t (le_bytes_to_nat64 (seq_uint8_to_seq_nat8 s)) | {
"checked_file": "Vale.Interop.Views.fsti.checked",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Interop.Views.fsti"
} | [
"total"
] | [
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"FStar.UInt64.uint_to_t",
"Vale.Def.Types_s.le_bytes_to_nat64",
"Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8",
"FStar.UInt64.t"
] | [] | module Vale.Interop.Views
module DV = LowStar.BufferView.Down
module BV = LowStar.BufferView.Up
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Def.Opaque_s
open Vale.Lib.Seqs_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Seq
open Vale.Def.Words.Four_s
module U8 = FStar.UInt8
let get8_def (s:Seq.lseq U8.t 1) = Seq.index s 0
[@"opaque_to_smt"] let get8 = opaque_make get8_def
irreducible let get8_reveal = opaque_revealer (`%get8) get8 get8_def
let put8_def (x:U8.t) : GTot (Seq.lseq U8.t 1) =
let contents (i:nat{i<1}) = x in
Seq.init 1 contents
[@"opaque_to_smt"] let put8 = opaque_make put8_def
irreducible let put8_reveal = opaque_revealer (`%put8) put8 put8_def
val inverses8 (u:unit) : Lemma (DV.inverses get8 put8)
let up_view8 = inverses8 (); BV.View 1 get8 put8
let down_view8 = inverses8 (); DV.View 1 put8 get8
let get16_def (s:Seq.lseq U8.t 2) = UInt16.uint_to_t (
U8.v (Seq.index s 0) +
U8.v (Seq.index s 1) * 0x100
)
[@"opaque_to_smt"] let get16 = opaque_make get16_def
irreducible let get16_reveal = opaque_revealer (`%get16) get16 get16_def
let put16_def (x:UInt16.t) : GTot (Seq.lseq U8.t 2) =
let s = Seq.create 2 (U8.uint_to_t 0) in
let x = UInt16.v x in
let s = Seq.upd s 0 (U8.uint_to_t (x % 0x100)) in
let x = x `op_Division` 0x100 in
let s = Seq.upd s 1 (U8.uint_to_t (x % 0x100)) in
s
[@"opaque_to_smt"] let put16 = opaque_make put16_def
irreducible let put16_reveal = opaque_revealer (`%put16) put16 put16_def
val inverses16 (u:unit) : Lemma (DV.inverses get16 put16)
let up_view16 = inverses16 (); BV.View 2 get16 put16
let down_view16 = inverses16 (); DV.View 2 put16 get16
let get32_def (s:Seq.lseq U8.t 4) =
UInt32.uint_to_t (four_to_nat 8 (seq_to_four_LE (seq_uint8_to_seq_nat8 s)))
[@"opaque_to_smt"] let get32 = opaque_make get32_def
irreducible let get32_reveal = opaque_revealer (`%get32) get32 get32_def
let put32_def (x:UInt32.t) : GTot (Seq.lseq U8.t 4) =
seq_nat8_to_seq_uint8 (four_to_seq_LE (nat_to_four 8 (UInt32.v x)))
[@"opaque_to_smt"] let put32 = opaque_make put32_def
irreducible let put32_reveal = opaque_revealer (`%put32) put32 put32_def
val inverses32 (u:unit) : Lemma (DV.inverses get32 put32)
let up_view32 = inverses32(); BV.View 4 get32 put32
let down_view32 = inverses32(); DV.View 4 put32 get32 | false | false | Vale.Interop.Views.fsti | {
"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"
} | null | val get64_def : s: FStar.Seq.Properties.lseq FStar.UInt8.t 8 -> FStar.UInt64.t | [] | Vale.Interop.Views.get64_def | {
"file_name": "vale/specs/interop/Vale.Interop.Views.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: FStar.Seq.Properties.lseq FStar.UInt8.t 8 -> FStar.UInt64.t | {
"end_col": 64,
"end_line": 69,
"start_col": 2,
"start_line": 69
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.